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:
parent
010701ca98
commit
1d4a06efa8
@ -84,11 +84,12 @@ export const ChildForm: React.FC<ChildFormProps> = ({ child, onSubmit, supportin
|
||||
/>
|
||||
<FormInput id="birthday"
|
||||
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}
|
||||
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')}
|
||||
/>
|
||||
<FormInput id="phone"
|
||||
register={register}
|
||||
|
@ -24,12 +24,13 @@ type FormInputProps<TFieldValues, TInputType> = FormComponent<TFieldValues> & 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 = <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);
|
||||
|
||||
/**
|
||||
@ -102,7 +103,8 @@ export const FormInput = <TFieldValues extends FieldValues, TInputType>({ id, re
|
||||
placeholder={placeholder}
|
||||
accept={accept}
|
||||
maxLength={maxLength}
|
||||
max={max} />
|
||||
max={max}
|
||||
min={min}/>
|
||||
{(type === 'file' && placeholder) && <span className='fab-button is-black file-placeholder'>{placeholder}</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>}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user