How to I access the Selectize instance to use the API

How to I access the Selectize instance to use the API

bigbenchrobbigbenchrob Posts: 26Questions: 9Answers: 2

I'd like to alter some aspects of a Selectize field using the API. In answer to a previous question, Alan, you suggested accessing the API using the Selectize plug-in inst() method. I assume the API can only be accessed once the field has actually been generated on the editing form. So I'm trying the following, which is not working. Hopefully a basic lack of understanding on my part? Thanks.

editor = new $.fn.dataTable.Editor( {

    //...etc    
};

editor.on( 'open', function ( e, type ) {

    var fieldSelect = editor.field("field_id_65").inst();
    console.log(fieldSelect.getValue());
} );

//CONSOLE: TypeError: fieldSelect.getValue is not a function

This question has accepted answers - jump to:

Answers

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

    Hi,

    I've just completely rewritten the plug-in to address this and a few other little things I found along the way. The inst() method will now return the expected instance, and also you don't need to use the open event anymore.

    Allan

  • bigbenchrobbigbenchrob Posts: 26Questions: 9Answers: 2

    You rock, Allan! Thanks very much.

  • munnsjmunnsj Posts: 7Questions: 1Answers: 1

    Hi Allan,

    What else did this rewritten plugin change? I have code that worked on Friday and foolishly updated without saving the previous version of the plugin. None of my "opts" work anymore. I had placeholder text and a dynamic search load written. I am trying to debug the library but am not sure where the "opts" arguments should be added to the Selectize element. Please help!

    Thanks

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

    Darn - sorry about that. I even remember making that mistake ("I'll just do this and come back to that...").

    I've just posted an update to the plug-in that should resolve it.

    Regards,
    Allan

  • munnsjmunnsj Posts: 7Questions: 1Answers: 1
    Answer ✓

    Thank you very much! It worked and the fast turnaround time is greatly appreciated.

This discussion has been closed.