Changing field type and data source in editor

Changing field type and data source in editor

epoch1epoch1 Posts: 17Questions: 8Answers: 1
edited April 2018 in Editor

I have a modal editor window with a select element, the options in the select are populated based on the logged in user's permissions. When the modal fires on create I want to display a select and when they click edit I want the select to be replaced with a read only text input.

I thought I could just use clear and add to switch the elements, then use data: in the add method to set the values - it will either be an array of values on create and single value (from the corresponding table row) on edit, the only way I could get it to work is as follows by using set and update to set the values, is there a better way to do this?

"initComplete": function (settings, json) {
            origSelect = json.options.origSelect; // Holds original select for initCreate
        }
    });

...

editor.on('initEdit', function(e, node, data) {  
  editor.clear('selectItem');
  editor.add({
        label: "Select Item:",
        name: "selectItem",
        type: "readonly",
        data: "selectItem" // should pick up from name by default?
    },'elementNo3');
  editor.field('selectItem').set(data.selectItem);
});

...

editor.on('initCreate', function( ) {
  editor.clear('selectItem');
  editor.add({
        label: "Select Item:",
        name: "selectItem",
        placeholder: "Select",
        type: "select",
        data: "selectItem"
    },'elementNo3');
editor.field('selectItem').update(origSelect);
});

Thanks

Answers

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin

    That looks like it is about as good as it gets if you want to change the actual type. However, would using disable() / enable() work for you? It would effectively make the select readonly.

    Allan

This discussion has been closed.