submit api method refactor
This commit is contained in:
		@@ -4,7 +4,8 @@ X-editable changelog
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Version 1.2.1 wip
 | 
					Version 1.2.1 wip
 | 
				
			||||||
----------------------------  
 | 
					----------------------------  
 | 
				
			||||||
[enh] removed default dataType='json' for submit request. Use 'ajaxOptions' to specify dataType if needed (vitalets) 
 | 
					[enh] removed dataType='json' from 'submit' api method. Use 'ajaxOptions' to specify dataType if needed (vitalets) 
 | 
				
			||||||
 | 
					[enh] removed dataType='json' from saving request. Use 'ajaxOptions' to specify dataType if needed (vitalets) 
 | 
				
			||||||
[enh] select: do not show 'sourceError' in element during autotext execution (vitalets) 
 | 
					[enh] select: do not show 'sourceError' in element during autotext execution (vitalets) 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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. 
 | 
					            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)
 | 
					            @method submit(options)
 | 
				
			||||||
            @param {object} options 
 | 
					            @param {object} options 
 | 
				
			||||||
            @param {object} options.url url to submit data 
 | 
					            @param {object} options.url url to submit data 
 | 
				
			||||||
            @param {object} options.data additional data to submit
 | 
					            @param {object} options.data additional data to submit
 | 
				
			||||||
            @param {object} options.ajaxOptions additional ajax options            
 | 
					            @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.error(errors) error handler 
 | 
				
			||||||
            @param {function} options.success(obj) success handler 
 | 
					            @param {function} options.success(response, config) success handler. Passing __config__ to be able to call error handler. 
 | 
				
			||||||
            @returns {Object} jQuery object
 | 
					            @returns {Object} jQuery object
 | 
				
			||||||
            **/            
 | 
					            **/            
 | 
				
			||||||
            case 'submit':  //collects value, validate and submit to server for creating new record
 | 
					            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'                        
 | 
					                        type: 'POST'                        
 | 
				
			||||||
                    }, config.ajaxOptions))
 | 
					                    }, config.ajaxOptions))
 | 
				
			||||||
                    .success(function(response) {
 | 
					                    .success(function(response) {
 | 
				
			||||||
                        //successful response 
 | 
					                        //successful response 200 OK
 | 
				
			||||||
                        if(typeof config.success === 'function') {
 | 
					                        if(typeof config.success === 'function') {
 | 
				
			||||||
                            config.success.apply($elems, arguments);
 | 
					                            config.success.call($elems, response, config);
 | 
				
			||||||
                        } 
 | 
					                        } 
 | 
				
			||||||
                    })
 | 
					                    })
 | 
				
			||||||
                    .error(function(){  //ajax error
 | 
					                    .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
 | 
					                } else { //client-side validation error
 | 
				
			||||||
                    if(typeof config.error === 'function') {
 | 
					                    if(typeof config.error === 'function') {
 | 
				
			||||||
                        config.error.call($elems, {errors: errors});
 | 
					                        config.error.call($elems, errors);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            return this;
 | 
					            return this;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -246,9 +246,8 @@ $(function () {
 | 
				
			|||||||
 
 | 
					 
 | 
				
			||||||
        $(fx).find('.new').editable('submit', {
 | 
					        $(fx).find('.new').editable('submit', {
 | 
				
			||||||
            url: 'new.php', 
 | 
					            url: 'new.php', 
 | 
				
			||||||
            error: function(data) {
 | 
					            error: function(errors) {
 | 
				
			||||||
               ok(data.errors, 'errors defined');
 | 
					               equal(errors.text, 'invalid', 'client validation error ok');
 | 
				
			||||||
               equal(data.errors.text, 'invalid', 'client validation error ok');
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
@@ -261,8 +260,19 @@ $(function () {
 | 
				
			|||||||
        $(fx).find('.new').editable('submit', {
 | 
					        $(fx).find('.new').editable('submit', {
 | 
				
			||||||
            url: 'new-error.php',
 | 
					            url: 'new-error.php',
 | 
				
			||||||
            data: {a: 123},
 | 
					            data: {a: 123},
 | 
				
			||||||
            error: function(data) {
 | 
					            success: function(data, config) {
 | 
				
			||||||
                equal(data.errors.text1, 'server-invalid', 'server validation error ok');
 | 
					                console.log(data);
 | 
				
			||||||
 | 
					               ok(data.errors, 'errors received from server');
 | 
				
			||||||
 | 
					               ok(typeof config.error === 'function', 'config passed correctly');
 | 
				
			||||||
 | 
					               
 | 
				
			||||||
 | 
					               if(data && data.id) { 
 | 
				
			||||||
 | 
					                  //success 
 | 
				
			||||||
 | 
					               } else if(data && data.errors){ 
 | 
				
			||||||
 | 
					                   config.error.call(this, data.errors); //call error from success
 | 
				
			||||||
 | 
					               }               
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            error: function(errors) {
 | 
				
			||||||
 | 
					                equal(errors.text1, 'server-invalid', 'server validation error ok');
 | 
				
			||||||
                e.remove();
 | 
					                e.remove();
 | 
				
			||||||
                e1.remove();
 | 
					                e1.remove();
 | 
				
			||||||
                start(); 
 | 
					                start(); 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user