Answer the question
In order to leave comments, you need to log in
How to make yii2 date validation work correctly?
Hello. Faced such a problem that the validation rules for the date field do not work.
Essence: there is a field "date of registration" and "date of dismissal". The first field is required, the second is not, but it must be checked that the registration date is less than the dismissal date.
In fact: when choosing any date of registration, an error pops up. The value of "Reg Date" must be less than the value of "Expel Date", no matter whether the correct date of dismissal is selected or not selected at all.
public function rules()
{
return
[
[['f_fio', 'i_fio', 'o_fio'], 'match', 'pattern' => '/^[A-Za-zА-Яа-яЁё\-\s\']*$/'],
[['f_fio', 'i_fio', 'sex', 'id_organization', 'reg_date', 'birthday'], 'required'],
['reg_date', 'compare', 'compareAttribute' => 'expel_date', 'operator' => '<'],
['expel_date', 'date', 'skipOnEmpty' => true],
[['specializations', 'o_fio', 'id_user', 'expel_date'], 'safe'],
];
}
Answer the question
In order to leave comments, you need to log in
I solved the problem on my own, this version of the validator helped:
Removed the line with skipOnEmpty, it is not needed
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question