zend-form icon indicating copy to clipboard operation
zend-form copied to clipboard

Calling SetValue on Element/DateSelect with an empty string set's to todays date

Open carnage opened this issue 10 years ago • 2 comments

If a DateSelect element has it's value set to an empty string, due to the behaviour of php's date time object; the element is set to today's date. See offending code:

https://github.com/zendframework/zend-form/blob/29a930f8a66cad97b727be8bad65b1f2e1d288f8/src/Element/DateSelect.php#L106

This may be considered desirable; however if the option create_empty_option is set to create a default empty option, this behaviour prevents the element from being set back to the empty option.

The fix would be to test for an empty string in that conditional, but is a potential BC break

carnage avatar Jul 15 '15 13:07 carnage

I don't think this is a bug, but rather expected behavior (in line with DateTime's behavior).

I'd rather suggest accepting null and then nulling all fields if that is the case.

Ocramius avatar Jul 15 '15 13:07 Ocramius

This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at https://github.com/laminas/laminas-form/issues/54.

michalbundyra avatar Jan 15 '20 19:01 michalbundyra