Select2 not picking up value or submitting onChange

Select2 not picking up value or submitting onChange

NewLISTNewLIST Posts: 7Questions: 3Answers: 0

Hey Allan, just purchased the Editor and it looks GREAT with Select2. However, the inline control is not picking up the current cell value (maybe because the cell is displaying the label?) and it doesn't submit when a new value is checked. How do I get Select2 to pickup the correct cell value and then submit on change or when a new Select2 value is selected?

{
    type    : 'select2',
    name    : 'locale',
    attr    : {'class' : 'form-control', 'data-name' : 'locale' },
    ipOpts  : options,
    opts    : {
                minimumResultsForSearch: -1  // gets rid of the search box
              }
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,765Questions: 1Answers: 10,111 Site admin
    Answer ✓

    How do I get Select2 to pickup the correct cell value

    It sounds like the values available in the select2 list might not contain the value given by locale. Might that be the case? Can you link to the page so I can take a look?

    submit on change or when a new Select2 value is selected

    You could try the submitOnBlur option of form-options (which can be set when you call inline(). Or you could add a change event handler that will call the submit() method.

    Regards,
    Allan

  • NewLISTNewLIST Posts: 7Questions: 3Answers: 0
    edited December 2014

    Okay, so ultimately, I just took charge of the controls and set things manually. The data I need to process is coming in from the server backwards from the way Editor is wanting to read it so that necessitated me setting the Select2 control manually. No biggie once I realized what was happening.

    I found a little array_flip() function on Stackoverflow that solved my issue nicely.

    // Activate an inline edit on click of a table cell for Select2 fields
    oMethods.oTable.on('click', 'tbody td.selectable', function ( event ) {
                    
         var submit = function(){
                        
            var locale = $(this).val();
            oMethods.editor
                    .set( 'field', 'locale' )
                    .set( 'locale', locale )
                    .submit(); 
                        
        };
                    
        var label   = $( this ).html();
        var locales = oMethods._array_flip( $.parseJSON( $( '#languages' ).val() ) );
                    
        oMethods.editor.inline( this );
                    
        $( this ).find( 'select' ).one( 'change', submit );
        $( this ).find( 'select' )
                .select2( 'val', locales[label] )
                .select2( 'open' );
                            
                    
    });            
    
  • allanallan Posts: 61,765Questions: 1Answers: 10,111 Site admin

    Great - good to hear you managed to get it resolved, and thanks for posting your code!

    Allan

This discussion has been closed.