zendframework / zend-form

Form component from Zend Framework
BSD 3-Clause "New" or "Revised" License
69 stars 87 forks source link

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

Open carnage opened 9 years ago

carnage commented 9 years ago

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

Ocramius commented 9 years ago

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.

michalbundyra commented 4 years ago

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.