How set readOnly dynamically in record.js?

I'm need set readOnly in custom field when logged user not admin in record.js

if(app.user.get('type') == 'admin')
  //set readOnly field
else
  //set editable fiel

Parents Reply
  • Thanks for helping us.

    I've got the follwing code to make the fields read-only mode. It used to work on versions before 7.8.

    I've added the this._renderHtml and this._renderFields to get part of it work.

    Once you open the record (in this case an Opportunity) and the condition is true, the Cancel, Save and Edit buttons are visible, all at the same time.

    Cancel, Save and Edit buttons are visible when conditions are true.

    What would be the best approach to make it work properly?

    ...
    ({
       extendsFrom: 'RecordView',
       initialize: function (options) {
       this._super('initialize', [options]);
       this.model.on('data:sync:complete', this.readOnlyFieldsOpp, this);
    },

    _renderHtml: function(options) {
       this._super("_renderHtml", [options]);
    },

    readOnlyFieldsOpp: function() {
       var readonly = this.model.get('opp_readonly_c');

       this._render();
       if (readonly === true){
       _.each(this.model.fields, function(field) {
       if (field.name != "opp_readonly_c"){
       this.noEditFields.push(field.name);
       }
       },this);
       this._renderHtml();
       this._renderFields();
       }
       },

    })

Children