submit api method refactor

This commit is contained in:
vitalets
2012-12-07 21:02:24 +04:00
parent da910f5d94
commit e79605fad6
3 changed files with 23 additions and 12 deletions

@ -423,15 +423,15 @@ Makes editable any HTML element on the page. Applied as jQuery method.
/**
This method collects values from several editable elements and submit them all to server.
It is designed mainly for <a href="#newrecord">creating new records</a>.
Internally it runs client-side validation for all fields and submits only in case of success.
@method submit(options)
@param {object} options
@param {object} options.url url to submit data
@param {object} options.data additional data to submit
@param {object} options.ajaxOptions additional ajax options
@param {function} options.error(obj) error handler (called on both client-side and server-side validation errors)
@param {function} options.success(obj) success handler
@param {function} options.error(errors) error handler
@param {function} options.success(response, config) success handler. Passing __config__ to be able to call error handler.
@returns {Object} jQuery object
**/
case 'submit': //collects value, validate and submit to server for creating new record
@ -452,9 +452,9 @@ Makes editable any HTML element on the page. Applied as jQuery method.
type: 'POST'
}, config.ajaxOptions))
.success(function(response) {
//successful response
//successful response 200 OK
if(typeof config.success === 'function') {
config.success.apply($elems, arguments);
config.success.call($elems, response, config);
}
})
.error(function(){ //ajax error
@ -464,7 +464,7 @@ Makes editable any HTML element on the page. Applied as jQuery method.
});
} else { //client-side validation error
if(typeof config.error === 'function') {
config.error.call($elems, {errors: errors});
config.error.call($elems, errors);
}
}
return this;