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
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
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 consolethis.model.attributes.sales_status
It comes up with "Closed Won", but when I haveconsole.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?
You would want to wait for the data:sync:complete event to fire.
Here is an example of its use:
Thanks for the reply. When should I use this method of making fields readonly vs using sugarlogic and custom dependencies? Or is there no real difference?
There definitely is a difference. This particular approach is only feasible if you are only concerned about the behavior of the field within the main web app and only within that specific view. In other words, that same field would appear as an editable field were you to look at it via SugarCRM Mobile.
Likewise, this approach has some greater flexibility in other areas when compared to dependencies. For example, you could examine the current user and determine whether the field should or shouldn't be read only based solely off of that.
In short, there are some trade-offs with each approach and Mobile tends to be the area of concern. If you are not using Mobile (or don't plan on doing so), which option you choose is a lesser concern.
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.
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();
}
},
})
Hi Angel Martinez.
I'm trying to use your method to disable some fields.
I have tabs on my record view, but when using "this.renderHtml();", there ain't nothing tab selected, and the buttons "Cancel", "Save" and "Edit" shows the same time.
Do you have some idea to improve this?
Regards!
Any reason to don't apply dependency ReadOnly?
Hi André!
I need to control some fields depending on various things; current user type, a specific registration status, etc.
But I already made it, using the next code:
hideFields: function(_fieldsArray) {
_fieldsArray.forEach(function(field) {
var element = self.getField(field);
element.setDisabled(true);
});
},
Now, I neet to make read only some subpanels of the record.
Regards.
Hi André!
I need to control some fields depending on various things; current user type, a specific registration status, etc.
But I already made it, using the next code:
hideFields: function(_fieldsArray) {
_fieldsArray.forEach(function(field) {
var element = self.getField(field);
element.setDisabled(true);
});
},
Now, I neet to make read only some subpanels of the record.
Regards.
We had implemented sugarLogic functions which evaluates attributes of authenticated user, like roles, teams, user_name, type etc, so you would be able to invoke such sugarLogic functions in order to decide whether to trigger a ReadOnly action from inside a regular dependency.
Regards
Oh ok!
Could you share me, some example to use these sugarLogic functions inside a regular dependency?
Regards