2
votes

In a form, I have a multiple select, where the input can have 0 or X values.

Problem is, if user doesn't send value, in ajax, the variable is an empty array and it is not sent in the request : the object property is not set to null and it keeps its old value, and validation keeps ok.

The only trick I found is to send a variable [0], and in this case it works.

Do you have any idea how can I empty an object property in validation ?

1

1 Answers

1
votes

Please read about Zend\Filter\Null: https://packages.zendframework.com/docs/latest/manual/en/modules/zend.filter.set.html#null

Per default this filter works like PHP‘s empty() method; in other words, if empty() returns a boolean TRUE, then a NULL value will be returned.

If you use this filter in your Input Filter for this field, it will return a null instead of an empty array.