NicolasCARPi / jquery_jeditable

jQuery edit in place plugin. Extendable via plugin architecture. Plugins for plugin. Really.
https://jeditable.elabftw.net
MIT License
1.74k stars 458 forks source link

How do we catch the "id" of the edited control when submitting to a custom function? #233

Closed carlosalvidrez closed 3 years ago

carlosalvidrez commented 3 years ago

Description

How do we catch the "id" of the edited control when submitting to a custom function? Thanks!

NicolasCARPi commented 3 years ago

See: https://github.com/NicolasCARPi/jquery_jeditable/#submitting-to-function-instead-of-url

carlosalvidrez commented 3 years ago

Thanks for the quick response... I implement that, but I can't find the original element's id in any of the function accessible objects... neither "this", "value" or "settings". I realize I might be missing something. I'm just stomped.

Great work by the way, thanks for sharing!

NicolasCARPi commented 3 years ago

That would be $(this).attr('id').

carlosalvidrez commented 3 years ago

Great, thanks!

carlosalvidrez commented 3 years ago

Hi Nicolas, just wanted to let you know I tried it, and I'm still not able to get the id, or any other attribute from the node being edited. Here is a quick snippet showing you everything I tried. Hope you can shed some light into this or publish a basic example showing this succeeding. Thanks!!

$('.editable').editable(
    (value, settings) => {

        const new_value = value.trim();

        console.log(sn, "- this:", $(this));
        console.log(sn, "- this 2:", this);
        console.log(sn, "- this id:", $(this).attr('id'));
        console.log(sn, "- this id v2:", this.parentNode.getAttribute('id'));
        console.log(sn, "- this id v2:", $(this).parentNode.getAttribute('id'));
        console.log(sn, "- this data-assignment-id:", $(this).attr('data-assignment-id'));
NicolasCARPi commented 3 years ago

I suspect it's because you're using an arrow function, and it impacts what is "this". Try with a normal function.

carlosalvidrez commented 3 years ago

That was it! Thank you. I appreciate your follow-up. Great library, thanks again!