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
  • You should be able to adapt this Gist to do what you want:

    Custom record view controller for setting entire record to read-only conditionally · GitHub

    They key is to add the field name into the "noEditFields" array.

  • Hi
    This code works for me in 7.8 when I pause it at breakpoints. However it appears that this javascript is running before the model has been loaded, hence I get
     this.model.attributes.sales_status is undefined
    When I run it without breakpoints.

    When I insert a breakpoint and type in the javascript console
    this.model.attributes.sales_status
    It comes up with "Closed Won", but when I have
    console.log(this.model.attributes.sales_status)
    it just prints undefined.
    Is there a way to make sure this only runs once the model has been fully loaded?

    Also is it preferred to set fields to readonly using this method or sugarlogic dependencies?

  • Hi,

    Try 

     this.$('.record-edit-link-wrapper[data-name=' + field.name + ']').remove();
    instead of
    self.noEditFields.push(field.name); As this will not work on 7.8.. versions.
    Also disable edit and save action.
    $('.headerpane a[name=edit_button]').addClass("disabled");
    $('.headerpane a[name=save_button]').addClass("disabled");
    var self = this;
    _.each(this.model.fields, function(field) {
        //self.noEditFields.push(field.name);
        this.$('.record-edit-link-wrapper[data-name=' + field.name + ']').remove();
    },this);

    Regards,

    Usman

  • Hi,Usman

    this Solution failed ......

    Working Normal screen Fine ...

    but after press edit button and back browser button then all fields makes editable....

Reply
  • Hi,Usman

    this Solution failed ......

    Working Normal screen Fine ...

    but after press edit button and back browser button then all fields makes editable....

Children