Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X-Editable bootstrap plugin "hidden" event issue on dynamically added elements

I cannot get x-editable`s "hidden" event to work on dynamically added classes (or fields) via JS. I can manage it to work only if I add editable classes straight on HTML, but this approach is not suitable for me. What am I doing wrong?

$.fn.editable.defaults.mode = "inline";
$.fn.editable.defaults.onblur = "submit";

$(document).ready(function () {
    $('.field').each(function() {
        $(this).addClass('editable');
    });
    $('.editable').editable();
});

$(document).on('hidden', '.editable', function(e, params) {
    alert('was hidden!');
});

Fiddle: http://jsfiddle.net/4vj8buks/17/

like image 688
gzzz Avatar asked May 15 '15 11:05

gzzz


1 Answers

You can hook into the editable's hidden event like this:

$.fn.editable.defaults.mode = "inline";
$.fn.editable.defaults.onblur = "submit";

$(document).ready(function () {
    $('.field').each(function() {
        $(this).addClass('editable');
    });

    $('.editable').editable().on('hidden', function (e, params) {
        alert('was hidden!');
    });
});
like image 177
tdbts Avatar answered Nov 04 '22 01:11

tdbts