Access x-editable dynamically generated form or input

坚强是说给别人听的谎言 提交于 2019-12-12 01:46:13

问题


Upon clicking an element, x-editable creates an input element. Within the validate callback, how can I access that element? I "could" do so by assigning a unique class using inputclass to each time the plugin is applied to an element, however, this offers very little flexibility. Within the call back, this references the original element, not the input element.

https://jsfiddle.net/cgym6m3v/1/

<p>Name</p><a href="javascript:void(0)" id="name"></a>

$('#name').editable({
    type: 'text',
    title: 'Name',
    url: '/echo/json/',
    pk: 123,
    validate: function (value) {
        console.log(this,value);
    }
});

回答1:


I don't think this is the cleanest solution, but it will work. Maybe there isn't a clean solution at all...

$('.bla').editable({
    inputclass: function(e, f) {
        $("a[aria-describedby=" + $(this).closest(".ui-tooltip").prop("id") + "]").data("shared", this);
    },
    validate: function (value) {
        console.log("validate", $(this).data("shared"));
    }
});

https://jsfiddle.net/cgym6m3v/5/



来源:https://stackoverflow.com/questions/29566417/access-x-editable-dynamically-generated-form-or-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!