Skip to content

Commit

Permalink
Keep the value of the input-box locally as well to solve the caret
Browse files Browse the repository at this point in the history
  • Loading branch information
asheshv committed Sep 2, 2024
1 parent 3ff9916 commit 1ed674f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions web/pgadmin/static/js/components/FormComponents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,21 @@ export const InputText = forwardRef(({
cid, helpid, readonly, disabled, value, onChange, controlProps, type, size, inputStyle, ...props }, ref) => {

const maxlength = typeof(controlProps?.maxLength) != 'undefined' ? controlProps.maxLength : 255;

const patterns = {
'numeric': '^-?[0-9]\\d*\\.?\\d*$',
'int': '^-?[0-9]\\d*$',
};
let onChangeFinal = (e) => {

let finalValue = (_.isNull(value) || _.isUndefined(value)) ? '' : value;

if (controlProps?.formatter) {
finalValue = controlProps.formatter.fromRaw(finalValue);
}

if (_.isNull(finalValue) || _.isUndefined(finalValue)) finalValue = '';

const [val, setVal] = useState(finalValue);
const onChangeFinal = (e) => {
let changeVal = e.target.value;

/* For type number, we set type as tel with number regex to get validity.*/
Expand All @@ -371,14 +380,10 @@ export const InputText = forwardRef(({
if (controlProps?.formatter) {
changeVal = controlProps.formatter.toRaw(changeVal);
}
setVal(changeVal);
onChange?.(changeVal);
};

let finalValue = (_.isNull(value) || _.isUndefined(value)) ? '' : value;

if (controlProps?.formatter) {
finalValue = controlProps.formatter.fromRaw(finalValue);
}

const filteredProps = _.pickBy(props, (_v, key)=>(
/* When used in ButtonGroup, following props should be skipped */
Expand Down Expand Up @@ -406,7 +411,7 @@ export const InputText = forwardRef(({
disabled={Boolean(disabled)}
rows={4}
notched={false}
value={(_.isNull(finalValue) || _.isUndefined(finalValue)) ? '' : finalValue}
value={val}
onChange={onChangeFinal}
{
...(controlProps?.onKeyDown && { onKeyDown: controlProps.onKeyDown })
Expand Down

0 comments on commit 1ed674f

Please sign in to comment.