select2 createTag issue with editor

select2 createTag issue with editor

loukinglouking Posts: 259Questions: 52Answers: 0

Trying to get select2 createTag to work per https://select2.org/tagging. I get error at dataTables.editor.js line 5275 because canReturnSubmit not defined for the field.

found https://datatables.net/forums/discussion/comment/140478/#Comment_140478, but not sure the correct setting. In any case the select2 fieldtype plugin should be updated if canReturnSubmit is required

Else dataTables.editor.js should verify function exists before calling it

See https://codepen.io/louking/pen/LMGVJm, and enter some new option into the select search box for col0

This question has an accepted answers - jump to answer

Answers

  • loukinglouking Posts: 259Questions: 52Answers: 0

    actually this issue occurs with or without createTag, so the subject is a bit misleading

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Found a couple issues:

    1. You are loading select2.js twice with two different versions. Probably should only load it once
    2. You are loading the editor editor.select2.js plugin before loading dataTables.editor.js

    I reversed the load order for 2 and commented out the second select2.js in 1, you will see the comments:
    https://codepen.io/anon/pen/MZKoMB?editors=1010#0

    The example seems to work now.

    Kevin

  • loukinglouking Posts: 259Questions: 52Answers: 0

    Thanks for looking at this and fixing some typos, but your version still has the problem.

    Uncaught TypeError: field.canReturnSubmit is not a function
        at HTMLDocument.<anonymous> (dataTables.editor.js:5275)
        at HTMLDocument.dispatch (jquery-3.1.0.min.js:3)
        at HTMLDocument.q.handle (jquery-3.1.0.min.js:3)
    
  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited December 2018

    I think either https://editor.datatables.net/plug-ins/field-type/editor.select2 (and other plugins?) should be extension of baseFieldType defined at dataTables.editor.js 8985, or line 5275 should be similar to line 5289.

    Probably also https://editor.datatables.net/manual/development/field-types should be updated to be extension of baseFieldType if that's the correct solution.

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Uncaught TypeError: field.canReturnSubmit is not a function

    I tried again but don't see that error. How do your recreate in the updated example?

    Kevin

  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited December 2018

    bring up console, click New, click on the select2 control, type 'test' in the search box, hit carriage return

    I use chrome development tools which default to stop on exception. console should show the error in any case.

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Right, hitting return makes sense. I was clicking out of the cell :smile:

    I'm not sure what the issue is. I have a select2 field configured similarly with tags but don't have the issue. However I am using an old version of Editor (1.6.2) on that page.

    Maybe @allan or @colin can find something.

    Kevin

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    100% agree - this is an error in Editor I'm afraid. There is a keydown event handler which calls canReturnSubmit - that is where the error is coming from and it should check for the function. If you find:

                    if ( field.canReturnSubmit( el ) ) {
                        e.preventDefault();
                    }
    

    and replace it with:

                    if ( field && typeof field.canReturnSubmit === 'function' && field.canReturnSubmit( el ) ) {
                        e.preventDefault();
                    }
    

    That will do it.

    Regards,
    Allan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Sorry - I forgot to add, Kevin won't see this in 1.6.x since the key handling was modified since then.

    Allan

This discussion has been closed.