Zend Framework

Zend_Dojo does not set required="false" if explicitly set

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9.0
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Dojo
  • Labels:
    None

Description

There is a minor problem with the decorator in Zend_Dojo_Form_Decorator_DijitElement:

Some Dijit form elements - like the number spinner - need an explicit "required=false" in order to accept blank values. This might be necessary if an input is optional and the user enters the input box but decides to exit it without entering a value. Therefore, the value is still empty but e.g. the number spinner validates and rejects the blank value.

If one sets "required=false" this problem does not exist.

The abovementioned decorator already sets required to true if explicitly set, but does not do so for false. Therefore, we need to change this behaviour in order to get the desired behaviour.

Careful: The decorator needs to set the value "false" as a String, not a boolean one. If set to boolean, it will be evaluated to 0 or "" (empty string) which will not be recognized by dojo.

I will attach my modified file. Please let me know whether this bug will be addressed in one of the next patches.

  1. DijitElement.php
    22/Aug/09 8:58 AM
    6 kB
    Christian Heinrich
  2. ZF-7660.possible.patch
    21/Dec/09 3:08 PM
    1 kB
    Menno Luiten

Activity

Hide
Max Gordon added a comment -

The numberspinner issue is a Dojo issue see http://trac.dojotoolkit.org/ticket/9643. Will be fixed in 1.4

Show
Max Gordon added a comment - The numberspinner issue is a Dojo issue see http://trac.dojotoolkit.org/ticket/9643. Will be fixed in 1.4
Hide
Matthew Weier O'Phinney added a comment -

Resolved by patching Dijit view helper; "required" attribute is always cast to a string now. Patch applied to trunk and 1.9 release branch.

Show
Matthew Weier O'Phinney added a comment - Resolved by patching Dijit view helper; "required" attribute is always cast to a string now. Patch applied to trunk and 1.9 release branch.
Hide
Dolf Schimmel (Freeaqingme) added a comment -

Reopened as per request (irc)

Show
Dolf Schimmel (Freeaqingme) added a comment - Reopened as per request (irc)
Hide
Micah Gersten added a comment -

I am still experiencing this on 1.9.6 with a Dojo Subform and a Filtering Select. I pass 'required' => false, in the initialization array for the form field, but it is still being required.

Show
Micah Gersten added a comment - I am still experiencing this on 1.9.6 with a Dojo Subform and a Filtering Select. I pass 'required' => false, in the initialization array for the form field, but it is still being required.
Hide
Dolf Schimmel (Freeaqingme) added a comment -

Isn't this just a matter of an incorrectly set fix version?

Show
Dolf Schimmel (Freeaqingme) added a comment - Isn't this just a matter of an incorrectly set fix version?
Hide
Micah Gersten added a comment -

The fix attached to the bug works, while the fix that was committed does not.

Show
Micah Gersten added a comment - The fix attached to the bug works, while the fix that was committed does not.
Hide
Menno Luiten added a comment - - edited

Confirmed that the required="false" attribute will never be set (when set from the Element), since it does not set $attribs["required"] when $_required = false. This is because the parameter 'required' given to the Element calls 'setRequired()' rather than set the value in the $_attributes. Which is what happens when you give the exact same parameter from a Dojo ViewHelper like Zend_Dojo_View_Helper_NumberSpinner.

This would normally not be a problem if Dojo, just like ZF, assumes that an element is not required when the required attribute is not set. Unfortunately, like stated, this is not the case: FilteredSelect, NumberSpinner, TimeTextBox and maybe others assume that the element is required unless specifically told to. Might get fixed in Dojo 1.4 though?

So, imho, the attached patch is required to always set the required attribute on dojo elements. This might however, change the behavior of some elements (for the better; same required attribute for Zend_Form_Element and its Dojo counterpart, eliminating dependencies on Dojo's defaults), so not sure if it's possible to patch into 1.9 release. Maybe in time for 1.10??

Show
Menno Luiten added a comment - - edited Confirmed that the required="false" attribute will never be set (when set from the Element), since it does not set $attribs["required"] when $_required = false. This is because the parameter 'required' given to the Element calls 'setRequired()' rather than set the value in the $_attributes. Which is what happens when you give the exact same parameter from a Dojo ViewHelper like Zend_Dojo_View_Helper_NumberSpinner. This would normally not be a problem if Dojo, just like ZF, assumes that an element is not required when the required attribute is not set. Unfortunately, like stated, this is not the case: FilteredSelect, NumberSpinner, TimeTextBox and maybe others assume that the element is required unless specifically told to. Might get fixed in Dojo 1.4 though? So, imho, the attached patch is required to always set the required attribute on dojo elements. This might however, change the behavior of some elements (for the better; same required attribute for Zend_Form_Element and its Dojo counterpart, eliminating dependencies on Dojo's defaults), so not sure if it's possible to patch into 1.9 release. Maybe in time for 1.10??
Hide
Menno Luiten added a comment - - edited

Found a workaround: instead of passing required => false in the initialization (which calls setOptions, which in turn calls setRequired()), use the Element::setAttrib() function, like so

  • $dojoElement->setAttrib('required', false);
  • or: $dojoElement->setDijitParam('required', false);
  • or even: $dojoElement->setAttrib('dijitParams', array('required' => false));
Show
Menno Luiten added a comment - - edited Found a workaround: instead of passing required => false in the initialization (which calls setOptions, which in turn calls setRequired()), use the Element::setAttrib() function, like so
  • $dojoElement->setAttrib('required', false);
  • or: $dojoElement->setDijitParam('required', false);
  • or even: $dojoElement->setAttrib('dijitParams', array('required' => false));
Hide
Matthew Weier O'Phinney added a comment -

Fixed on trunk and 1.10 release branch.

Show
Matthew Weier O'Phinney added a comment - Fixed on trunk and 1.10 release branch.

People

Vote (1)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: