ZF-7660: Zend_Dojo does not set required="false" if explicitly set

Issue Type: Bug Created: 2009-08-22T08:56:10.000+0000 Last Updated: 2010-01-25T12:26:06.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Christian Heinrich (shurakai) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Dojo

Related issues: Attachments: - DijitElement.php


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.


Posted by Max Gordon (mgordon) on 2009-11-20T04:48:09.000+0000

The numberspinner issue is a Dojo issue see Will be fixed in 1.4

Posted by Matthew Weier O'Phinney (matthew) on 2009-11-20T09:20:21.000+0000

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

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-12-14T16:55:59.000+0000

Reopened as per request (irc)

Posted by Micah Gersten (micah26) on 2009-12-14T16:57:24.000+0000

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.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-12-14T17:00:49.000+0000

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

Posted by Micah Gersten (micah26) on 2009-12-15T13:09:37.000+0000

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

Posted by Menno Luiten (mluiten) on 2009-12-21T15:08:20.000+0000

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??

Posted by Menno Luiten (mluiten) on 2009-12-22T06:41:43.000+0000

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));

Posted by Matthew Weier O'Phinney (matthew) on 2010-01-25T12:26:05.000+0000

Fixed on trunk and 1.10 release branch.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.