how to change attribute of a field to hidden?

how to change attribute of a field to hidden?

FicosFicos Posts: 88Questions: 22Answers: 0

in editor I have some fields on initialisation. They will be populated onCreate. After creation (that is on editing the row) those fields should be hidden or readonly. How do I change this?

This question has an accepted answers - jump to answer

Answers

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

    Would be great if you had some code!

    But you can do this using an event e.g. this one: https://editor.datatables.net/reference/event/postCreate

    Here is an example from my coding with a different Editor event. I set, show and hide fields dynamically:

    myEditor
         .dependent('fixed.fee', function (val, data, callback) {
                var self = myEditor;
                if (val != 0 && val > '-') { //if the fee contains a not 0 value
                    self.show(['fixed.fee_date']);
                    if (self.val('fixed.fee_date') <= '') {
                        self.field('fixed.fee_date').set(inTwoDays);
                    }
                } else {
                    self.set({'fixed.fee_date': ''})
                            .hide(['fixed.fee_date']);
                }
            })
    

    Take a look at the api Field instance methods to see how to show, hide, set, get field values.
    https://editor.datatables.net/reference/api/

  • FicosFicos Posts: 88Questions: 22Answers: 0

    It was even more simple as I thought. I need to give password a vulue for a new record, but hide the field when editing, so the password can not be changed:
    ~~~js
    membersEditor
    .on( 'open', function (e, d, action) {
    var pwd = $.generateRandomPassword(8);
    if(action=='create'){
    membersEditor.field('members.password').val( pwd );
    }
    else{
    membersEditor.hide(['members.password']);
    }
    });
    ~~ ~
    Thanks for your help

This discussion has been closed.