TextBase::addFilter breaks the client side validation?
- peci1
- Member | 60
I've come to a difficult situation in my form. It looks like a design flaw to me.
I have a date field represented as TextInput where the date format should be
17. 11. 1989
. And I want to have a filter on this field, which
would convert the date to the classical Y-m-d H:i:s
format.
Server validation is okay when you perform it first in the filter method (by
using an if
) and the validation method checks the validity of the
filtered value (e.g. the filter returns unfiltered value if the if
doesn't succeed).
However, on client side, there is no filtration happening. Therefore, if I set the validator to validate the filtered values, it just fails on client side.
Apparently, there is the need to perform validation both before and after the filtration takes place. And on client side, only validation before filtration should be done.
Or is there any other solution I don't see?
PS: I've looked to the two Datepicker addons and both of them have some kind
of workaround and do not use addFilter
at all.
- David Grudl
- Nette Core | 8218
Yes, it is design flaw, because addFilter has not counterpart in JavaScript. Therefore addFilter is now obsolete and you should filter values inside (own) validators. Like Nette itself does https://github.com/…369c97ea0cf2.