user1032531
user1032531

Reputation: 26331

Add parameter to x-editable params

x-editable has the option() method which is used to set a new option. params is one of the options and happens to be an object, and instead of replacing params with a new object, I just want to add a property to the existing params object. Below is my attempt, but I am inadvertently overwriting params and not adding a new property as desired.

http://jsfiddle.net/fo1susa1/

$(function() {

    $('#name').editable({
        url: '/echo/json/',
        pk: 123,
        params:{a:1,b:2}
    })
    .on('shown', function(e, editable) {
        editable.option('params', {c:3});
    });

});

Upvotes: 4

Views: 7567

Answers (1)

tdbts
tdbts

Reputation: 525

You can add a property to the existing params object like this:

$(function() {

    $('#name').editable({
        url: '/echo/json/',
        pk: 123,
        params:{a:1,b:2}
    })
    .on('shown', function(e, editable) {
        editable.options.params.c = 3;
        // editable.options.params is now {a: 1, b: 2, c: 3}
    });

});

Hope this helps.

Upvotes: 9

Related Questions