Using ajax: Values of a form’s fields to an Ajax call using Dojo on newest questions tagged ajax – Stack Overflow

I have a form like this:
(From a widget template)

   '<div>' +
    '  <form data-dojo-type="dijit.form.Form" data-dojo-attach-point="form" method="POST"> ' +
    '    <label for="${id}_workspace">Workspace name</label>  ' +
    '    <input name="workspace" id="${id}_workspace" data-dojo-attach-point="workspace" data-dojo-type="app.ValidationWorkspace" />' +
    '    <label for="${id}_password1">Password</label>  ' +
    '    <input name="password[0]" id="${id}_password1" data-dojo-attach-point="password1" data-dojo-type="app.ValidationPassword" />' +
    '    <label for="${id}_password1">Confirm password</label>  ' +
    '    <input name="password[1]" id="${id}_password2" data-dojo-attach-point="password2" data-dojo-type="app.ValidationPassword" />' +
    '    <input type="submit" data-dojo-attach-point="button" data-dojo-type="app.BusyButton" label="Create!" />' +
    '  </form>' +
    '</div>',

In the code, I wrote:

        data = {};
        data.workspace = that.workspace.get('value');
        data.password = [];
        data.password[0] = that.password1.get('value');
        data.password[1] = that.password2.get('value');

        // Store the data
        g.stores.workspacesAnon.put(data).then(
          function(res){
            console.log("Jsonrest put(data) returned OK: " + json.toJson(res) );
            that.button.cancel();
          }
        );

Two actual questions:

1) If I use that.form.value.email instead of that.password1.get(‘value’), sometimes outdated values are submitted to the form (!). For example, if I type something in the password2 field and hit enter straight away, the actual submission happens for the previous value of the field (!). Is this something to be expected in Dojo? How come does it happen?

2) Is there a better way to get the form’s values, so that ‘password[0]‘ and ‘password[1]‘ become an array automatically etc.?

Hints?

Merc.

See Answers


source: http://stackoverflow.com/questions/11818837/values-of-a-forms-fields-to-an-ajax-call-using-dojo
Using ajax: using-ajax



online applications demo