This first post will deal with limiting which fields a user can edit as many of the form security applied previously does not apply to Editable Grids. What do I mean by this? First off read only attributes applied to fields on a form do not honor this setting in editable grids. As such neither does calls to setDisabled in form js. Also as editable grids are set at an entity level, users are able to create their own views and add any column, even those not on any form, to those views and gain editable rights to them. Supposedly field level security is upheld on editable grids, but that does little to help if you don't want to go through the thousands of fields you have created and decide who has access to edit them.
The first step I took is to disable all fields in the selected row. I will not go into how to setup editable grids or wire up events as this is all documented nicely many places, but where I ran into trouble is what the js should look like to accomplish this goal.
var editableFields = ["emailaddress1", "telephone1"];
function Grid_And_Form(executionContext) {
var entityObject = executionContext.getFormContext().data.entity;
var attributes= entityObject.attributes.getAll();
for (var i = 0; i< attributes.length; i++) {
if (editableFields.indexOf(attributes[i].getName()) == -1) {
console.log(attributes[i].getName());
var attrControl= attributes[i].controls.get(0);
attrControl.setDisabled(true);
}
}
}
By passing executionContext to the js, and retrieving the entity we can get all attributes. From there getting the first control for each attribute (there should only ever be one, as you cannot add a field to a view multiple times) we are able to disable that field. Creating a list up front of fields we want to allow to be editable allows us to easily modify the list, and document which fields are available.
No comments:
Post a Comment