Updates a DOM element with the response from the submission of a form (via Ajax).
Demo
Implements
Syntax
new Form.Request(form, update[, options]);
Arguments
- form - (mixed) A form Element or the string id of a form Element to manage submissions.
- update - (mixed) An Element or the string id of an Element to update with the response.
- options - (object, optional) The options object described below:
Options
- requestOptions - (object) The options passed on to the instance of [Request.HTML] created by the class that sends the form. Defaults to {evalScripts: true, useSpinner: true, url:
, emulation: false, spinnerTarget: .} - extraData - (object) An optional set of key/value pairs to be included with the form data submitted to the server. If keys in this collide with data in the form, the form values will be preserved and the extraData discarded.
- resetForm - (boolean) If true (the default), the form is reset when the request is sent.
Events
- send - (function) The function to execute when the request is sent. Passed the form being submitted and the data (an object) being submitted.
- failure - (function) The function to execute when the request fails. Passed the XHR that is returned by Request on failure.
- success - (function) The function to execute when the request succeeds. Passed the target being updated, the request text, and the request xml.
Form.Request integrates with Form.Validator to prevent the ajax being sent if the validation fails. It retrieves the Form.Validator instance from the form, so all that is required is that you instantiate the Form.Validator before you instantiate the instance of Fudpate. If the instance of Form.Validator has the stopOnFailure option set to true (the default) then Form.Request will not send the ajax request if the validator fails.
Changes the target that the instance will update with the Request response.
Syntax
myformUpdate.setTarget(newTarget);
Arguments
- newTarget - (mixed) An Element or the string id of an Element to update with the response.
Returns
- (object) - This instance of Form.Request
Sends the form.
Syntax
myformUpdate.send();
Returns
- (object) - This instance of Form.Request
Detaches the Form.Request from the form (disabling the ajax).
Syntax
myformUpdate.disable();
Returns
- (object) - This instance of Form.Request
Attaches the Form.Request to the form (enabling the ajax). Note that this is done on instantiation, so you only need to use this method if you disable the Form.Request instance and want to re-enable it.
Syntax
myformUpdate.enable();
Returns
- (object) - This instance of Form.Request
Extends the Element Type with a reference to its Form.Request instance and a method to create one.
Creates a new instance of Form.Request and calls its send method.
Syntax
$(element).formUpdate(update, options);
Arguments
- update - (mixed) An Element or the string id of an Element to update with the response.
- options - (object) a key/value set of options. See [Form.Request:options][].
Returns
- (element) This Element.
Example
$(element).formUpdate($('myDiv'), { requestOptions: {useSpinner: false } });
Syntax
myForm.retrieve('form.request'); //the instance of Form.Request for the element