laminas / laminas-form

Validate and display simple and complex forms, casting forms to business objects and vice versa
https://docs.laminas.dev/laminas-form/
BSD 3-Clause "New" or "Revised" License
80 stars 52 forks source link

Date/Time selects helpers __invoke args may have no effect #233

Closed pine3ree closed 1 year ago

pine3ree commented 1 year ago

As explained in the issue title we can call for invoke FormDateTimeSelect. with a few arguments:

    public function __invoke(
        ?ElementInterface $element = null,
        int $dateType = IntlDateFormatter::LONG,
        int $timeType = IntlDateFormatter::LONG,
        ?string $locale = null
    ) {
   //...

but in doing that getPattern() is called internally which result is cached to the internal property pattern with the values for dateType, timeType and locale of its first call. https://github.com/laminas/laminas-form/blob/d20ba468fad89a23e68ed679b6b827543e166afa/src/View/Helper/FormDateTimeSelect.php#L180

We should either remove the cache property (from the base abstract helper) or stale/reset its value to null when calling either setDateType() or setTimeType() or setLocale().

This affects all AbstractFormDateSelect descendants, namely: FormMonthSelect, FormDateSelect and FormDateTimeSelect

This also affects calling render() after calling setDateType() or setTimeType() or setLocale(), as the internal pattern is cached during the 1st rendering call with the values of $dateType, $timeType, $locale at that time.