Skip to content

Commit 05d9cde

Browse files
authored
Merge pull request #38 from coder966/dev
v2.4.2
2 parents 55700e4 + 7391c54 commit 05d9cde

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
Pre-release versions will not be mentioned here.
44

5+
## [2.4.2] - 2025-04-27
6+
7+
### Fixed
8+
9+
- `RruDateTimeInput`: Fixed validation would trigger even before touching the field.
10+
11+
## Other
12+
13+
- Internal enhancements.
14+
515
## [2.4.1] - 2024-11-02
616

717
### Fixed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-rich-ui",
3-
"version": "2.4.1",
3+
"version": "2.4.2",
44
"description": "React UI framework with lots of built-in UI components (forms, data table, steps wizards, etc...)",
55
"keywords": [
66
"React",

src/form/RruDateTimeInput/RruDateTimeInput.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const RruDateTimeInput: FC<RruDateTimeInputProps> = (props) => {
5050
const popupRef = useDetectClickOutside({
5151
onTriggered: (e) => {
5252
if (e.target != inputRef.current) {
53-
closePopup();
53+
setIsPopupShown(false);
5454
}
5555
},
5656
});
@@ -79,11 +79,6 @@ const RruDateTimeInput: FC<RruDateTimeInputProps> = (props) => {
7979
}
8080
};
8181

82-
const closePopup = () => {
83-
setIsPopupShown(false);
84-
field.onBlur();
85-
};
86-
8782
const previousMonth = () => {
8883
if (month === 1) {
8984
setYear(year - 1);
@@ -107,7 +102,8 @@ const RruDateTimeInput: FC<RruDateTimeInputProps> = (props) => {
107102
return;
108103
} else {
109104
setIntlDate(date);
110-
closePopup();
105+
setIsPopupShown(false);
106+
field.onBlur();
111107
}
112108
};
113109

@@ -168,7 +164,7 @@ const RruDateTimeInput: FC<RruDateTimeInputProps> = (props) => {
168164
onIntegerInputChange(matches[6], 0, 59, setMinute);
169165
onIntegerInputChange(matches[7], 0, 59, setSecond);
170166
}
171-
}else{
167+
} else {
172168
setYear(today.getYear(getCalendarType()));
173169
setMonth(today.getMonth(getCalendarType()));
174170
}

src/form/hooks/useField.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { useFormContext, useFormState, useWatch } from 'react-hook-form';
1919
import { resolveObjectAttribute } from '../../utils/utils';
2020

2121
/**
22+
* @param name field name
2223
* @param onProgrammaticValue Should check if the provided serialized value does not
2324
* match the current deserialized value before updating the formContext, otherwise you would end up in an infinite re-render
2425
*/
@@ -29,12 +30,6 @@ export const useField = (name: string, onProgrammaticValue?: (serializedValue: a
2930
const [isTouched, setIsTouched] = useState<boolean>(false);
3031
const watchResult = useWatch({ name: name });
3132

32-
if (name && name.split('.').filter((p) => /\d+/.test(p)).length > 0) {
33-
console.error(
34-
`Field name "${name}" cannot include a numeric part. Try to prefix the numeric part with some string.`
35-
);
36-
}
37-
3833
useEffect(() => {
3934
if (isRegistered.current && onProgrammaticValue) {
4035
onProgrammaticValue(watchResult);
@@ -47,6 +42,12 @@ export const useField = (name: string, onProgrammaticValue?: (serializedValue: a
4742
return;
4843
}
4944

45+
if (name && name.split('.').filter((p) => /^\d+$/.test(p)).length > 0) {
46+
console.error(
47+
`Field name "${name}" cannot include a numeric part. Try to prefix the numeric part with some string.`
48+
);
49+
}
50+
5051
const initialValue = formContext.formState.defaultValues
5152
? resolveObjectAttribute(name, formContext.formState.defaultValues)
5253
: undefined;

stories/Form.RruForm.stories.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import {
2727
RruMultiSelectInput,
2828
RruRadioInput,
2929
RruSelectInput,
30-
RruTextInput,
3130
RruTextareaInput,
31+
RruTextInput,
3232
useRruForm,
3333
} from '../src/index';
3434
import animalsOptions from './data/animalsOptions';
@@ -533,3 +533,27 @@ export const SetValueProgrammaticallyAllTypes = (args) => {
533533
</RruForm>
534534
);
535535
};
536+
537+
export const ValidateFieldNames = (args) => {
538+
const rruFormContext = useRruForm();
539+
540+
const onSubmit = (form) => {
541+
action('submitting the form')(form);
542+
};
543+
544+
return (
545+
<RruForm
546+
context={rruFormContext}
547+
onSubmit={onSubmit}>
548+
549+
<RruTextInput name='email' label='Email' requiredAsterisk />
550+
<RruTextInput name='color1' label='Email' requiredAsterisk />
551+
<RruTextInput name='animal.1' label='Email' requiredAsterisk />
552+
553+
<button type='submit' className='btn btn-primary mt-4'>
554+
Submit
555+
</button>
556+
557+
</RruForm>
558+
);
559+
};

0 commit comments

Comments
 (0)