Login Register

Form Widget

This Document is Out of Date. For the current documentation, please see http://docs.dojocampus.org/

Although you're not required to place Dijit form elements in a dijit.form.Form, doing so gets you some nice methods and extension points to use.

dijit.form.Form
Adds conveniences to regular HTML form.
Methods
getValues generate JSON structure from form values get widget values
isValid Return true if every widget's isValid method returns true.
setValues fill in form values from a JSON structure generate map from name --> [list of widgets with that name]
submit programatically submit form
Extension Points
execute User defined function to do stuff when the user hits the submit button

Callbacks?

By Callback do you mean Extension Point? It would be really nice to have an example here as well. Or, maybe even better, is extend the first example in "Part 1: Life with Dojo" to at least show the Dojo way of controlling form submission. Thanks.

getValues/setValues working in 1.0?

I can't get getValues() to work with checkboxes (haven't tried other form inputs yet), and I see large "TODO" items in both setValues() and getValues() in the Form.js source. Is this supposed to be supported? Or should we use dojo.formToObject() instead?

Examples?

I can not find one example of using this dijit anywhere for forms -- can anyone point me in the right direction? Perhaps an example is needed on this page?

Thanks.

This may be helpful,

This may be helpful, although its intended purpose is for doh testing, so some of the source should be ignored:

http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/form/Form...

Ah!

Yes very helpful - thx!

getValue() and setValue()

I found that in dojo release 1.1.1 getValues() and setValues() are no more available but getValue() and setValue() instead

How to Validate Form

Iam new to dojo. i know this is question may asked earlier but i didn't find it so i post it here.
How to validate the dojo form w/o using json string data.
or
is we can validate dojo form only if we are providing json string data?
if no can anyone tell me how to restrict the user to submit form if inputs are invalid.

<button> </button> element inside the form

If you want xhr calls initiated from a button, make sure the button is outside
the <form dojoType="dijit.form.Form"> <form>
<button> </button> element inside the form will cause the form to submit
and load the whole new page. Even if you specify onclick
<button onclick="dojo.xhrPost({'url:page.php, handleAs: json, etc..
(other args)'})" >, that onclick will be useless you will scratch your head
why a whole new page is loaded when you just actually called an xhrPost()..

Button inside form

If you want to initiate an xhr call from a form, you can put the button inside the form: Leave the type of button as submit, and on the form itself specify the "onSubmit" attribute to call the function you want to run the xhr from. Just don't fill in the "action" attribute of the form and this should work fine.

If you do it any other way (onClick via the button for example), you get the weird side effect of only submitting the form when clicking on the button and not via carriage return inside the form elements.