Support for Editor + Select2 in Tags Mode

Support for Editor + Select2 in Tags Mode

webusr91webusr91 Posts: 12Questions: 5Answers: 0

Hi,

Trying to use Select2 Plugin with Datatable Editor with following options,

    {  
        "name": "selectField1", 
        "type": "select2",                                          
        "opts": {
                 "tags": true, 
                  "multiple": true,         // Support entering multiple tags
                 "tokenSeparators": [',']  // using , as delimiter                                                              
         }   
    }

With above configuration, when providing initial table data as

"selectField1": ["value1","value2"]

Not getting any these of these options in Select2 dropdown when trying to edit column values.

Wanted to check if Editor can support Select2 with "tags" mode, without any initial options, with user able to enter multiple new values, different ones for each row.

Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    I'm not aware of any compatibility issues with Editor and Select2's options. Are you able to give a link showing the issue so I can check it out?

    If not, I'll set up a local example during the week.

    Thanks,
    Allan

  • webusr91webusr91 Posts: 12Questions: 5Answers: 0

    Please find attached sample HTML code

    I am using editor in inline editing model.

    For all other fields, Editor is working good with inline mode.

    For "selectField1", i am trying to have it running with Select2, "tags" mode. (tags mode goal: User can enter list of options dynamically with no predefined drop down values, separate ones for each row)

    Even though i am providing initial values for "selectField1", these are not being shown when i click to edit that field.

    Also when click on this column and enter values "test1","test2" then these are getting added successfully. But when i click on another row, and then click back on previous row, then values are being lost. (with local storage enabled)

    Thanks

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Sorry for the delay! Busy times :smile:.

    So the issue here is that your Select2 list doesn't have any values available to be selected. It is correctly trying to set the values, but the options list is empty (think of it basically as a simple HTML select element - in this case it has no values that can be selected).

    To fix your example add the options that can be selected to the Select2 field:

    options: [
        'value1', 'value2', 'value3', 'value4'
    ]
    

    Your actual solution will presumably be a touch more complicated, but basically you need to list the options that the field can take.

    If you are using the Editor PHP or .NET libraries the Options class can be used to populate options based on values in a database.

    Allan

This discussion has been closed.