Validate rules and reactdatepicker configuration #7772
-
Hi. I'm having trouble customizing a donation form. So far, I have created 2 custom fields : date and text :
I'm currently stuck to limit birthday selection to years overs 18 and to check the values. reactdatepicker, used in the date field, is able to exclude date intervals: It seems that Give has tools to validate rules (->rules() / HasValidationRules), but I can't find resources to make it work. Kind regards. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@g3r0me you can use a custom rule closure. You can learn more about our validation library we use for our fields here. \Give\Framework\FieldsAPI\Date::make('birthday')
->rules(function ($value, Closure $fail, string $key, array $values) {
$today = new DateTime('today');
$date = new DateTime($value);
if ($date->diff($today)->y < 18) {
$fail('You must be at least 18 years old to donate.');
}
});
\Give\Framework\FieldsAPI\Text::make('id_num')
->rules(function ($value, Closure $fail, string $key, array $values) {
$today = new DateTime('today');
$date = new DateTime($values['birthday']);
if ($date->diff($today)->y < 18) {
$fail('You must be at least 18 years old to donate.');
}
}); |
Beta Was this translation helpful? Give feedback.
-
It solves my birthday vérification. Thank you for your help. |
Beta Was this translation helpful? Give feedback.
@g3r0me you can use a custom rule closure. You can learn more about our validation library we use for our fields here.