Magicsuggest / magicsuggest

Multiple Selection Combo Box using Bootstrap 3
nicolasbize.com/magicsuggest/
1.3k stars 269 forks source link

Unable to get values on change #288

Open msoffen opened 7 years ago

msoffen commented 7 years ago

I have a page whith 3 magicSuggest widgets on it. One for 3 different business groups.

The Groups are identical (but need to be tracked as Business Owner, Point of Contact, IT Contact...

I'll focus on just one of them (Business Owner)...

I have this jquery code... I know the /get_org.php is returning the correct data (for the value/display fields and the data DOES display properly)...

var bo = $(function(){ $('#businessowner').magicSuggest({ allowFreeEntries: true, data: '/get_org.php', // Simple query to return the Org Data. method: 'post', required: true, valueField: 'org_id', displayField: 'org_desc' }); });

$(bo).on('triggerclick', function(){
    console.log('BusinessOwner Data - Change');
    alert(JSON.stringify($('#businessowner').getValue()));
});

$('#businessowner').on('selectionchange', function(e,m){
    //alert("values: " + bo.getValue());
    alert ("Save Data for Business Owner....");
});

And the HTML for this is: `

` I want it to save the data on change so that if you modify one of the other areas it will persist the data. For whatever the reason, I'm not getting the triggerclick or selectionchange events. Any suggedstions ?
msoffen commented 7 years ago

I answered my own question...

' var bobo; var bo = $(function(){ bobo = $('#businessowner').magicSuggest({ allowFreeEntries: true, data: '/get_org.php', // Simple query to return the Org Data. method: 'post', required: true, valueField: 'org_id', displayField: 'org_desc' });

    $(bobo).on('selectionchange', function(e,m){

        $.get('/secure/updateValues.php', 'uid=$uid&businessOwner='+bobo.getValue(), function(){
            alert(JSON.stringify(bobo.getValue()));
        })
    });
});

'

This now correctly is triggered when I change the select box.

The only odd behavior i find is that if you enter text (a valid entry from the pulldown) it stores the text (not the ID that is selected when you click on the text as you type.