Standalone editor issue using remove()

Standalone editor issue using remove()

mguinnessmguinness Posts: 85Questions: 12Answers: 1

Having an issue when using editor remove() with Simple standalone editing. If the selector is keyless then after the record is deleted you get the following client side exception: "Uncaught TypeError: K(...).remove is not a function"

Looking at the source code I think the problem is that the _htmlId function returns the Root element when the identifier is keyless. This means that the following editor function calls jQuery remove() on the root element which will fail.

remove: function (identifier, fields) {
    // If there is an element with an ID property matching the identifier,
    // remove it
    _htmlId(identifier).remove();
}

Is there a way to include a check on the returned element before calling remove()?

This question has an accepted answers - jump to answer

Answers

  • mguinnessmguinness Posts: 85Questions: 12Answers: 1
    edited February 2023

    I was able to modify the code to prevent the error:

    if ( identifier !== 'keyless' ) {
        _htmlId(identifier).remove();
    }
    

    Also I added the following to the remove function:

    // no item given
    if (!items) {
        items = 'keyless';
    }
    

    Can these changes be merged into your codebase?

  • allanallan Posts: 63,569Questions: 1Answers: 10,481 Site admin

    If an item is keyless, it wasn't really designed to be deleted - only edited. Can you give me an over view of how you are using Editor in this context, for removing something that doesn't have a primary key value?

    Allan

  • mguinnessmguinness Posts: 85Questions: 12Answers: 1

    It's for a system settings table to archive the record. I understand it's probably an edge case, but not throwing an exception would be desirable. Hopefully you can add the check so I won't need to apply this to each new release of Editor. If I can override this function that would be fine, but I don't think that is possible?

  • allanallan Posts: 63,569Questions: 1Answers: 10,481 Site admin
    Answer ✓

    Committed now - they'll be in Editor 2.1.1, which should drop next week.

    The only tweak I've made is in the remove() method is to check that it is in standalone mode before using the keyless string:

        if (! items && ! this.s.table) {
            items = 'keyless';
        }
    

    Thanks!

    Allan

  • mguinnessmguinness Posts: 85Questions: 12Answers: 1

    Thank you Allan, have a great weekend!

Sign In or Register to comment.