[英]Yii2 compare validator with null value
I am using a dateTimeComparealidator
and i have 4 fields to compare. 我正在使用
dateTimeComparealidator
,我有4个字段可以比较。
1 . 1。
earlyOpenDate
(should be less than startDate
if its not null
) earlyOpenDate
(如果不为null
则应小于startDate
)
2 . 2。
earlyCloseDate
(should be greater than earlyOpenDate
if its not null
) earlyCloseDate
(如果不为null
则应大于earlyOpenDate
)
3 . 3。
startDate
(should be greater than earlyOpenDate
if earlyOpenDate
is not null) startDate
(如果earlyOpenDate
不为null,则应大于earlyOpenDate
)
4 . 4。
endDate
(should be greater than endDate
) endDate
(应大于endDate
)
In this startDate
and endDate
are mandatory but other 2 are optional. 在此
startDate
和endDate
是必需的,而其他2是可选的。
So my validator doesnt work when i have null
value in earlyOpenDate
. 所以当我在
earlyOpenDate
具有null
值时,我的验证器earlyOpenDate
。
When i select any value in startDate
it throws error that startDate
should be greater than earlyOpenDate
. 当我在
startDate
选择任何值时,会引发错误,提示startDate
应该大于earlyOpenDate
。
Is there any way without modifying the validator class to achieve this. 有什么办法可以不修改验证器类来实现这一点。
And also when i select the endDate
without selecting startDate
it displays error message but when i select the startDate
after selecting endDate
the message it still there until i reselect the date. 而且,当我选择
endDate
而不选择startDate
它也会显示错误消息,但是当我在选择endDate
之后选择startDate
,消息仍然存在,直到我重新选择日期为止。
It doesnt automatically invoke the validation. 它不会自动调用验证。
i am using this extension for datetime validation 我正在使用此扩展程序进行日期时间验证
I also tried to use 'when' validator with condition in yii2
but its not working as expected. 我还尝试在
yii2
使用带条件的“何时”验证器,但它无法按预期工作。
尝试重新执行skipOnEmpty
(应为默认值,但扩展名可以重新定义默认值)和/或相关的skipOnError
:
[..., 'skipOnEmpty' => true, 'skipOnError' => ...],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.