select2 plug-in selected property

select2 plug-in selected property

clazetteclazette Posts: 26Questions: 7Answers: 2

I can select options and save data. However, when I load the editor, the selected values for a given record are not indicated. If I change the field type to a checkbox, the correct checkboxes are checked when the editor form loads. What needs to be done in order to get selected values for the select2 field type?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Could you link to the page so I can debug that please. I'm not aware of an issue with the Select2 plug-in for Editor that would cause that.

    Allan

  • clazetteclazette Posts: 26Questions: 7Answers: 2

    Allan,
    I don't have anything publicly available. Is there some other way I can get you the information that you need to help?

    This is the same issue as 88642 but I wanted to get it logged under Editor as well. My apologies for the duplicate.

    Chad

  • clazetteclazette Posts: 26Questions: 7Answers: 2
    edited February 2016

    Hey Allan, this is my most pressing issue at the moment. If I can figure out why options are set to selected when the editor loads, that would be awesome. Is there anything special that I need to do? Do I just not have something configured properly in order to make that happen?

    A standard select as the type doesn't appear to work either. I have to be doing something wrong.

    In fact, a standard select won't even persist the data. The select2 is working aside from its inability to set selected for the applicable options.

    {
                    "label": "Area(s):",
                    "name": "areas[].ID",
                    "type": "select2",                                                      
                    "opts": {
                                "placeholder":     "Select Area(s)",
                                "allowClear":      true,
                                "multiple":        true//,
                                //"tags":            true,
                                //"tokenSeparators": [',', ' ']
                            }             
                },
    
    
    "type": "select",
                    attr: {"multiple": true} 
    
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    There shouldn't be anything special you need to do. You need to make sure that the values being used (areas[].ID) are the values that Select2 is being populated with. What are you using to populate the options?

    Allan

  • clazetteclazette Posts: 26Questions: 7Answers: 2

    This join...

    ->join(
                Mjoin::inst( 'areas' )
                    ->link( 'operators.ID', 'operator_areas.operator_ID' )                    
                    ->link( 'areas.ID', 'operator_areas.area_ID' )                
                    ->fields(
                        Field::inst( 'ID' )
                            ->validator( 'Validate::notEmpty' )
                            ->options( 'areas', 'ID', 'area_desc', 
                                       function($q){ $q->where('areas.active', true ); // Ensure only active areas are in the editor select.
                            } ),
                        Field::inst( 'area_desc' ) // supports display in DataTable not Editor.                                            
                    )
                    ->where('areas.active', true) // ensures only active areas are displayed in the table.
            )
    
    
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Hi,

    Just to check - you noted in one of your other threads that your other issues had been resolved. Does that include this one?

    The above does look like it should work!

    Allan

  • clazetteclazette Posts: 26Questions: 7Answers: 2
    Answer ✓

    Yes sir, this is the same issue and can be closed.

    Thank you,
    Chad

This discussion has been closed.