Hi,
I have an application which has to allow for a user to search for an occupation, with or without an occupation_group filter.
Using a Select2 field to select a filter for the search works fine.
However, if the user decided not to use a filter, the occupation_group field needs to be set to the appropriate group for the chosen occupation.
Here is my code:
// Set the value of the title and description fields when the template changes
editor.dependent( 'occupation_id', function ( val ) {
$.each(select_options, function( key,result ) {
if(result.id == val) {
editor.val('title',result.text); // Works!
editor.val('description',result.description); // Works!
//** Doesn't work**: editor.val('occupation_group_id',{value:result.occupation_group_id, label:result.occupation_group} );
// **Doesn't work:** $('#DTE_Field_occupation_group_id').select2('data', {id: result.occupation_group_id, text: result.occupation_group});
$('#DTE_Field_occupation').select2('close'); // Works!
filter = '';
}
});
});
I have checked that the result contains the required information. "title" is a text field, and "description" is a textarea, and they are set to the correct values. "occupation_group_id" is a Select2 field.
I would really appreciate any pointers.