-- Martin Carpentier <[email protected]> wrote
(on Monday, 16 November 2009, 02:44 PM +0100):
> Hi Matthew,
> 
> thanks for the reply.
> 
> I have this function setup in my view script
> 
> 
> dojo.addOnLoad(function () {
>     dojo.connect(dijit.byId("formSomething"), "onSubmit", "validateForm");
> 
> 
> }
> );
> function validateForm() {
>     var form = dijit.byId("formSomething");
>     if (!form.validate()) {
>         return false;
>     }
>     return true;
> 
> }
> 
> 
> All the elements get validated on the submit except for the radio buttons.
> 
> Do I have to add javascript code specificaly for  the validation of the radio
> buttons ?

I looked in the Dojo API docs for RadioButton. It inherits from
CheckBox, which inherits from ToggleButton, which inherits from Button.
None of these dijit types has validators. As such, when the form
validates, nothing is performed on the RadioButton.

If you want some sort of validation, you'll need to extend the dijit and
add an isValid() method that defines the validation action to perform;
then use your new widget with the form.

> On Mon, Nov 16, 2009 at 14:40, Matthew Weier O'Phinney <[email protected]>
> wrote:
> 
>     -- 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/
> 
> 

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

Reply via email to