editor 2.1.2 upgrade, field plugin select2 error.

editor 2.1.2 upgrade, field plugin select2 error.

casuistcasuist Posts: 41Questions: 16Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
aught TypeError: this.field is not a function
at Object.set (editor.select2.js:178:30)
at R.update (editor.select2.js:308:37)
at O._typeFn (dataTables.editor.min.js:6:64085)
at O.update (dataTables.editor.min.js:6:62292)
at O.<anonymous> (dataTables.editor.min.js:6:39240)
at Function.each (vendor.min.js:148:24)
at R.Ce [as _optionsUpdate] (dataTables.editor.min.js:6:39155)
at HTMLDocument.<anonymous> (dataTables.editor.min.js:6:74864)
at HTMLDocument.dispatch (vendor.min.js:1612:261)
at v.handle (vendor.min.js:1574:93)

    set: function (conf, val) {
        ****var field = this.field(conf.name); <-- error!!!!!!!!****

        if (conf.separator && !Array.isArray(val)) {
            val = val === null
                ? []
                : val.split(conf.separator);
        }

        // Clear out any existing tags
        if (conf.opts && conf.opts.tags) {
            conf._input.val([]);
        }

Description of problem:
1.9.6 editor and old plugin select2 script ok!
but 2.1.2 upgrade and new select2 script that error.
how??

This question has accepted answers - jump to:

Answers

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

    That's surprising! It seems to work for me locally here with 2.1.2, and checking the code it should do. this, in that context is the host Editor, and it does have a field() method.

    Can you PM me a link to your page so I can debug it please?

    Thanks,
    Allan

  • casuistcasuist Posts: 41Questions: 16Answers: 0

    Message sent.
    Thanks for your help.

  • wouterwouter Posts: 22Questions: 7Answers: 0

    I think this could be the same problem i addressed here:
    https://datatables.net/forums/discussion/76184/select2-with-options-in-php#latest

    In my case it has something to do with the options being declared in the php file. If i take them out it works like expected.

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

    @wouter - Apologies. I totally missed your thread on this topic.

    I think you've nailed the issue - the update isn't calling the set method with the correct scope.

    Replace:

    _fieldTypes.select2.set( conf, null );
    

    with

    _fieldTypes.select2.set.call( this, conf, null );
    

    And that will fix it. I'll get the site updated with that change.

    Allan

    edited Corrected order!

  • wouterwouter Posts: 22Questions: 7Answers: 0

    Hey Allan,

    Cool! I think you mean the other way araound, right?

    Replace:

    _fieldTypes.select2.set( conf, null );
    

    With:

    _fieldTypes.select2.set.call( this, conf, null );
    

    Because that works for me ;)

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

    Doh - yes! Thanks and good to hear that fixed it.

    Allan

  • casuistcasuist Posts: 41Questions: 16Answers: 0

    Ok! i fixed it.
    but bootstrap5 theme not work. maybe z-index problem.
    i add css this.
    .select2-dropdown {
    z-index: 1061;
    }
    z-index: 1051 -> 1061

    Now Work correct.

    Thanks!!!!

Sign In or Register to comment.