Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x-editable access attribute value of trigger element

I am using x-editable for in-line editing inside my web app. I would like to pass additional parameters to server, which I would like to read from data- attributes on trigger element. Here is my editable element:

<a href="#" data-url="save_url" data-pk="271" data-type="text" data-value="Value" class="editable" data-param="XXX">Value</a>

I would like to pass data-param attribute, but I don't know how to access trigger element. I tried via $(this).data('param'), but I get null... My full editable code:

$.fn.editable.defaults.mode = 'inline';
$('.editable').editable({
    params: { param: $(this).data('param') }
});

Calling $('.editable').data('param') doesn't come into account since I have many .editable elements present.

Thanks

like image 700
Primoz Rome Avatar asked May 09 '13 17:05

Primoz Rome


1 Answers

I figured it out. I'm answering in case somebody needs to know:

$('.editable').editable({
    params: function(params) {
        // add additional params from data-attributes of trigger element
        params.param1 = $(this).editable().data('param');
        params.param2 = $(this).editable().data('nextparam');
        return params;
    }
)
like image 127
Primoz Rome Avatar answered Oct 14 '22 20:10

Primoz Rome