Select2 issues

Select2 issues

tablotablo Posts: 58Questions: 13Answers: 0

Hi all,

I've set up Select2 and now I'm facing the following issues:
1..When I've selected some options and clicked on "Update", these options are saved and are visible in DataTables. Fine. When I open the Editor on this entry without touching anything in the dropdown and click "Update" then every option previously selected is being removed (from the DB too...). In other words, every time I open the Editor on this entry I have to select again the options I want, which is bothering. Is there a way to prevent this behavior?

2..My items in the dropdown are long lines, so the tag view is not very convenient . Is there another way to show the options, e.g. line by line ideally with a slider?

3..My items in the dropdown can be some hundreds. Is it possible to hide the options that I've already selected in the dropdown?

Answers

  • tablotablo Posts: 58Questions: 13Answers: 0

    When I use a local variable for the options instead of another DB column like this:

    var myOptions1 = ["Apple", "Orange"];
        ...
                {
                  label: "fruits:",
                  name: "fruits",
                  type: "select2",
                  options: myOptions1,
                  separator: ",",
                  opts: {
                    multiple: true,
                    placeholder: "Select fruits:"
                  }
    
    

    then issue nr.1 does not appear i.e. the options I've previously selected are not being removed every time I open the Editor for this item.

  • tablotablo Posts: 58Questions: 13Answers: 0

    I think I solved my first issue...

    When the options in the DB column are like this:

    Apple,Orange
    

    they are read as as string like this:

    "Apple,Orange"
    

    if I now convert this to an Array like this:

    var result;
    result = rowData["options"].split(",");
    editor.field("fruits").update(result);
    

    then they get written like this in the DB:

    {"Apple","Orange"}  
    

    when selected.
    I find this format weird, but at least they don't get removed. This without the separator activated. If I activate the separator with comma, like this:

    separator: ",",
    

    then they get removed again.

This discussion has been closed.