Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax PUT for submit #36

Closed
gbouteiller opened this issue Dec 5, 2012 · 3 comments
Closed

Ajax PUT for submit #36

gbouteiller opened this issue Dec 5, 2012 · 3 comments

Comments

@gbouteiller
Copy link

Hi,
First of all, I'd like to thank you for this great library.
I'd like to know if it is possible to let people use 'submit' with a 'PUT' verb (it seems like 'POST' is hardcoded). In fact, I want to update all my editable fields at once clicking on an 'update' button. Currently, I'm using your example for creating a new record but with the following url : /records/pk that I'd lijke to be associated with 'PUT'. Is it the right way to do it?
Thanks

@vitalets
Copy link
Owner

vitalets commented Dec 5, 2012

hi,
just checked - yes, for submit api method POST is hardcoded. I will definetly change it to be an option in next release.
As local solution you can use getValue method to collect data from editables and submit them via ajax.
(see how it done here https://github.com/vitalets/x-editable/blob/master/src/element/editable-element.js#L418)

For individual submit it is already done in 1.1.1, have a look on #22

Thank you.

@gbouteiller
Copy link
Author

What a quick answer! 👍
I've modified your code to use ajaxOptions in 'submit' : here what I've done :

(line 1425) case 'submit':  //collects value, validate and submit to server for creating new record
                var config = arguments[1] || {},
                $elems = this,
                errors = this.editable('validate'),
                values, ajaxOptions; // added var ajaxOptions

                if(typeof config.error !== 'function') {
                    config.error = function() {};
                } 

                if($.isEmptyObject(errors)) {
                    values = this.editable('getValue'); 
                    if(config.data) {
                        $.extend(values, config.data);
                    }
                    ajaxOptions = $.extend({ //extending ajax options with config.ajaxOptions
                        url     : config.url,
                        data    : values,
                        type    : 'POST',
                        dataType: 'json'
                    }, config.ajaxOptions); 
                    $.ajax(ajaxOptions).success(function(response) {

@thomas-louvigne
Copy link

thanks, it is exactly what i need !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants