1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-22 11:52:21 +01:00

(bug) child birthday < 18 years ago

This commit is contained in:
Du Peng 2023-05-29 14:41:30 +02:00
parent 010701ca98
commit 1d4a06efa8
3 changed files with 8 additions and 5 deletions

View File

@ -84,11 +84,12 @@ export const ChildForm: React.FC<ChildFormProps> = ({ child, onSubmit, supportin
/> />
<FormInput id="birthday" <FormInput id="birthday"
register={register} register={register}
rules={{ required: true, validate: (value) => moment(value).isBefore(moment().subtract(18, 'year')) }} rules={{ required: true, validate: (value) => moment(value).isAfter(moment().subtract(18, 'year')) }}
formState={formState} formState={formState}
label={t('app.public.child_form.birthday')} label={t('app.public.child_form.birthday')}
type="date" 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')}
/> />
<FormInput id="phone" <FormInput id="phone"
register={register} register={register}

View File

@ -24,12 +24,13 @@ type FormInputProps<TFieldValues, TInputType> = FormComponent<TFieldValues> & Ab
ariaLabel?: string, ariaLabel?: string,
maxLength?: number, maxLength?: number,
max?: number | string, max?: number | string,
min?: number | string,
} }
/** /**
* This component is a template for an input component to use within React Hook Form * This component is a template for an input component to use within React Hook Form
*/ */
export const FormInput = <TFieldValues extends FieldValues, TInputType>({ 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<TFieldValues, TInputType>) => { export const FormInput = <TFieldValues extends FieldValues, TInputType>({ 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<TFieldValues, TInputType>) => {
const [characterCount, setCharacterCount] = useState<number>(0); const [characterCount, setCharacterCount] = useState<number>(0);
/** /**
@ -102,7 +103,8 @@ export const FormInput = <TFieldValues extends FieldValues, TInputType>({ id, re
placeholder={placeholder} placeholder={placeholder}
accept={accept} accept={accept}
maxLength={maxLength} maxLength={maxLength}
max={max} /> max={max}
min={min}/>
{(type === 'file' && placeholder) && <span className='fab-button is-black file-placeholder'>{placeholder}</span>} {(type === 'file' && placeholder) && <span className='fab-button is-black file-placeholder'>{placeholder}</span>}
{maxLength && <span className='countdown'>{characterCount} / {maxLength}</span>} {maxLength && <span className='countdown'>{characterCount} / {maxLength}</span>}
{addOn && addOnAction && <button aria-label={addOnAriaLabel} type="button" onClick={addOnAction} className={`addon ${addOnClassName || ''} is-btn`}>{addOn}</button>} {addOn && addOnAction && <button aria-label={addOnAriaLabel} type="button" onClick={addOnAction} className={`addon ${addOnClassName || ''} is-btn`}>{addOn}</button>}

View File

@ -15,7 +15,7 @@ class Child < ApplicationRecord
# birthday should less than 18 years ago # birthday should less than 18 years ago
def validate_age 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 end
def full_name def full_name