diff --git a/app/frontend/src/javascript/components/family-account/child-form.tsx b/app/frontend/src/javascript/components/family-account/child-form.tsx index c65631d2c..02234f827 100644 --- a/app/frontend/src/javascript/components/family-account/child-form.tsx +++ b/app/frontend/src/javascript/components/family-account/child-form.tsx @@ -84,11 +84,12 @@ export const ChildForm: React.FC = ({ child, onSubmit, supportin /> moment(value).isBefore(moment().subtract(18, 'year')) }} + rules={{ required: true, validate: (value) => moment(value).isAfter(moment().subtract(18, 'year')) }} formState={formState} label={t('app.public.child_form.birthday')} type="date" - max={moment().subtract(18, 'year').format('YYYY-MM-DD')} + max={moment().format('YYYY-MM-DD')} + min={moment().subtract(18, 'year').format('YYYY-MM-DD')} /> = FormComponent & Ab ariaLabel?: string, maxLength?: number, max?: number | string, + min?: number | string, } /** * This component is a template for an input component to use within React Hook Form */ -export const FormInput = ({ id, register, label, tooltip, defaultValue, icon, className, rules, disabled, type, addOn, addOnAction, addOnClassName, addOnAriaLabel, placeholder, error, warning, formState, step, onChange, debounce, accept, nullable = false, ariaLabel, maxLength, max }: FormInputProps) => { +export const FormInput = ({ id, register, label, tooltip, defaultValue, icon, className, rules, disabled, type, addOn, addOnAction, addOnClassName, addOnAriaLabel, placeholder, error, warning, formState, step, onChange, debounce, accept, nullable = false, ariaLabel, maxLength, max, min }: FormInputProps) => { const [characterCount, setCharacterCount] = useState(0); /** @@ -102,7 +103,8 @@ export const FormInput = ({ id, re placeholder={placeholder} accept={accept} maxLength={maxLength} - max={max} /> + max={max} + min={min}/> {(type === 'file' && placeholder) && {placeholder}} {maxLength && {characterCount} / {maxLength}} {addOn && addOnAction && } diff --git a/app/models/child.rb b/app/models/child.rb index 07c59c4c6..3d752ac54 100644 --- a/app/models/child.rb +++ b/app/models/child.rb @@ -15,7 +15,7 @@ class Child < ApplicationRecord # birthday should less than 18 years ago def validate_age - errors.add(:birthday, I18n.t('.errors.messages.birthday_less_than_18_years_ago')) if birthday.blank? || birthday > 18.years.ago + errors.add(:birthday, I18n.t('.errors.messages.birthday_less_than_18_years_ago')) if birthday.blank? || birthday < 18.years.ago end def full_name