x-editable access attribute value of trigger element
Asked Answered
D

1

9

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

Denunciate answered 9/5, 2013 at 17:29 Comment(0)
D
18

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;
    }
)
Denunciate answered 15/5, 2013 at 15:8 Comment(3)
thousand thanks! This should be added to that XEditable library's doc too!Peale
When I try use this in the value parameter of editable() it errors 'undefined is not a function'Paraclete
@Paraclete you will have to share your code in order to help youDenunciate

© 2022 - 2024 — McMap. All rights reserved.