-- Martin Carpentier <[email protected]> wrote
(on Monday, 16 November 2009, 12:14 PM +0100):
> I'm bumping this topic as I haven't found a solution yet and have a hard time
> believing I'm the only one having to use required radio buttons in a form.

Do you have an onSubmit event that's performing form validation? If not,
then nothing special will happen.

> Anyone having a solution for this ?
> 
> Thanks,
> 
> Martin Carpentier
> 
> 
> On Tue, Nov 10, 2009 at 16:18, Martin Carpentier <[email protected]>
> wrote:
> 
>     Hi,
> 
>     I'm having a Zend_Dojo_Form with a RadioButton element defined like this:
> 
>     $options = array(
>         0 => 'no',
>         1 => 'yes',
>     );
> 
>     $this->addElement('RadioButton', 'elementName', array(
>         'label'          => 'some label',
>         'multiOptions'   => $options,
>         'required'       => true,
>     ));
> 
> 
>     My form displays correctly with the dojo enhancements but when I submit 
> the
>     form without selecting any of the radio button values, dojo doesn't flag
>     the element as being invalid.
>     I'm expecting it to be flagged with an error like the other required
>     elements that have been submitted without being filled.
> 
>     Here's my dojo declarations:
> 
>     dojo.require("dojo.i18n");
> 
> 
>     dojo.require("dijit.TitlePane");
>     dojo.require("dijit.form.CheckBox");
>     dojo.require("dijit.form.FilteringSelect");
>     dojo.require("dijit.form.DateTextBox");
>     dojo.require("dijit.form.ValidationTextBox");
> 
> 
>     dojo.require("dijit.form.Button");
>     dojo.require("dijit.form.Form");
>     dojo.require("dojo.parser");
> 
> 
>     I also have this form validation function set:
> 
> 
>     dojo.addOnLoad(function () {
> 
>         dojo.connect(dijit.byId("formSomething"), "onSubmit", "validateForm");
> 
>     }
>     );
>     function validateForm() {
>         var form = dijit.byId("formSomething");
>         if (!form.validate()) {
>             return false;
>         }
>         return true;
> 
>     }
> 
> 
> 
>     I noticed that the zendDijits js variable was set like this:
> 
> 
>     var zendDijits = 
> [{"id":"elementName","params":{"required":"true","dojoType":"dijit.form.RadioButton"}},{"id":"elementName-0","params":{"dojoType":"dijit.form.RadioButton"}},{"id":"elementName-1","params":{"dojoType":"dijit.form.RadioButton"}},
>  ... ];
> 
> 
> 
> 
>     The required flag is only set on the "main" elementName element but 
> doesn't
>     seem to be taken into account for the validation.
> 
>     So my question is, how can I make the RadioButton element being flagged as
>     required when none of it's values has been selected?
> 
>     Martin Carpentier
> 
> 

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to