Editor select and chosen plugin

Editor select and chosen plugin

Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

I am trying to find a way to dynamically pass a value, previous_tenant_id, from the currently being edited row into my chosen select option list for both inline editing and normal editing.

I know how to get the previous_tenant_id for both forms of editing like so,

        // get active previous_tenant_id
        editor.on('preSubmit', function(e, data, action) {
            if (action === 'edit') {
                var rowData = table.row(this.modifier()).data();
                if (typeof rowData != "undefined") {
                id = rowData.cms_module_system_tenancies.Id;
                previous_tenant_id = rowData.cms_module_system_tenancies.tenant_id;                                
                }
            }
        });        

        // get active previous_tenant_id inline        
        $('#cms_module_system_tenancies').on( 'blur', 'td', function () {
        var tr = this.parentNode;
        editor.inline( this );
        editor.one( 'preSubmit', function ( e, data ) {
        data.rowData = table.row( tr ).data();
        id = data.rowData.cms_module_system_tenancies.Id;
        previous_tenant_id = data.rowData.cms_module_system_tenancies.tenant_id;              
        });
        });

But I cannot figure out how to pass this value to my chosen select option list when that row has been selected.

I found this forum post https://datatables.net/forums/discussion/25855/with-chosen-plugin

// Get the select element
var select = $('select', editor.field('myFieldName').node() );
 
.. add options to the list / manipulate the select list ...
 
// Tell Chosen to update
select.trigger('chosen:updated');

But, I cant get the option list to update. Has anyone tried or achieved this who would be happy to share code?

Thanks

Replies

  • Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

    I don't know if this is correct but it seems to work initially.

    editor.on( 'initEdit', function ( e, node, data ) { 
    tenant_id = data.cms_module_system_tenancies.tenant_id;    
    tenant_forename = data.cms_module_system_users_tenants.forename;  
    tenant_surname = data.cms_module_system_users_tenants.surname;  
    if (tenant_forename !== '-') {   
    var select = $('select', editor.field('cms_module_system_tenancies.tenant_id').node() );
    var newOption = $('<option value="'+tenant_id+'" selected>'+tenant_forename+' '+tenant_surname+'</option>');
    select.append(newOption);
    select.trigger("chosen:updated");
    }
    });   
    

    However, I do end up with a long list of new options, I guess I need to remove the previous last new item before adding a new one.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Sorry - I thought I'd replied to this question on Friday - apparently not!

    What you have looks good - you might need to clean out the select list first if required.

    Did you try using the update method of the plug-in type as well? Or do you not what it to do a full update?

    Allan

This discussion has been closed.