Skip to content

Commit d98d2c5

Browse files
immediately trigger custom validation on input change
1 parent 16e8b29 commit d98d2c5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

client/packages/lowcoder/src/comps/comps/textInputComp/textInputConstants.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
requiredPropertyView,
3333
} from "comps/utils/propertyUtils";
3434
import { trans } from "i18n";
35-
import { ChangeEvent, useRef, useState } from "react";
35+
import { ChangeEvent, useEffect, useRef, useState } from "react";
3636
import { refMethods } from "comps/generators/withMethodExposing";
3737
import { InputRef } from "antd/es/input";
3838
import {
@@ -168,17 +168,22 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
168168
const propsRef = useRef<RecordConstructorToView<typeof textInputChildren>>(props);
169169
propsRef.current = props;
170170

171-
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
172-
props.value.onChange(e.target.value);
173-
propsRef.current.onEvent("change");
171+
const inputValue = props.value.value;
172+
173+
useEffect(() => {
174174
setValidateState(
175175
textInputValidate({
176176
...propsRef.current,
177177
value: {
178-
value: e.target.value,
178+
value: inputValue,
179179
},
180180
})
181181
);
182+
}, [inputValue]);
183+
184+
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
185+
props.value.onChange(e.target.value);
186+
propsRef.current.onEvent("change");
182187
};
183188
return [
184189
{

0 commit comments

Comments
 (0)