Noob: Change field attr

Noob: Change field attr

a1730a1730 Posts: 13Questions: 4Answers: 0

Error messages shown:
None.
Description of problem:
I have an embarrassing newbie question.
How does one remove attributes on an Editor field.
I have a field defined as

{label: 'Company Code:', name: 'id', type: 'readonly', attr: {disabled: true, required: true}},

Editor, being a very efficient and faithful servant is not letting me touch that field when addin data.
So I thought I'd add an event handler...

   editor.on('initCreate', function (e, json, data) {
    editor.field('id') // <=== I don't know what to put here to remove type: 'readonly', attr: {disabled: true, required: true}
   });

Your feedback is appreciated.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406
    Answer ✓

    I have an embarrassing newbie question.

    That doesn't sound like that! To get to that problem you need to have done a couple of things with Editor, I guess :smile:

    I don't think you can actually change many Editor attributes later on, but you can always remove and add fields dynamically. ( Here is a link to an attribute - the options - that you can change, but not for the selectize field below: https://editor.datatables.net/reference/api/field().update() )

    Here is an example in which I read the options dynamically from the server and then "clear" an existing field and "add" it back again in its position of "ctr.label_text_3".
    https://editor.datatables.net/reference/api/clear()
    https://editor.datatables.net/reference/api/add()

    editor
        .on('open', function (e, mode, action) {
            var that = this;
            $.ajax({
                type: "POST",
                url: 'actions.php?action=getCtrLinkOptions',
                data: {
                    ctr_id: action === "create" ? 0 : parentId
                },
                dataType: "json",
                success: function (data) {
                    that.clear( "ctr_has_ctr[].linked_ctr_id" );
                    that.add( {
                        label: lang === 'de' ? 
                                    'Wählen Sie einen oder mehrere zu verknüpfende Verträge:' : 
                                    'Please select one ore more contracts to be linked:',
                        name: "ctr_has_ctr[].linked_ctr_id", //render serial, name
                        type: "selectize",
                        options: data,
                        opts: {
                                create: false,
                                maxItems: null,
                                openOnFocus: true,
                                allowEmptyOption: true,
                                placeholder: lang === 'de' ? 
                                    'Keine verknüpften Verträge vorhanden' : 'No linked contracts exist'
                                }
                    }, "ctr.label_text_3" );
                    if ( columnEditing ) {
                        $('div.DTE_Body div.DTE_Body_Content div.DTE_Field').addClass("wide-modal");
                    } else {
                        $('div.DTE_Body div.DTE_Body_Content div.DTE_Field').addClass("two-cols");
                    }
                }
            });
        })
    
  • a1730a1730 Posts: 13Questions: 4Answers: 0

    Thank you:)
    That pointer worked.
    I couldn't find a way to target the field I wanted to remove, so, I used a big hammer because I only have three fields case. I need to learn how to target specific fields when there are more than five (5) fields. I know the information is in there somewhere because Editor documentation is very rich, and top notch... I just need to find it.

        const that = this
        that.clear() // <= BIG hammer
        .add({label: 'Company Code:', name: 'id', attr: {disabled: false, required: true}})
        .add({label: 'Company Name:', name: 'name', attr: {required: true}})
        .add({label: 'DUNS Number:', name: 'duns', attr: {required: true, type: 'number'}})
    
    

    It worked! I really need to understand Editor better.
    Thank you for the help.

Sign In or Register to comment.