Hi Devs,
I have a use case where I need to let the user edit fields and then depending on some conditions, the fields are set to read only. I've set it up in a dynamic handler but I've found that if I refresh the entire page using the browser refresh button, all the fields that are supposed to be read-only revert back to being editable even though the dynamic handler code is rerunning.
My code is much more complex than this but I've created the simplest possible example to test it using an entity with just two fields.
My entity:
ClientDefs:
And a dynamic handler:
When I run a php rebuild.php this works properly and sets the readOnly field to readonly. But if I refresh the page in the browser, the dynamic handler runs (I can see the logging in the console) but the readOnly field is editable again.
Am I doing something wrong?
I am on version 7.5.5 of Espo.
Cheers,
Clare
I have a use case where I need to let the user edit fields and then depending on some conditions, the fields are set to read only. I've set it up in a dynamic handler but I've found that if I refresh the entire page using the browser refresh button, all the fields that are supposed to be read-only revert back to being editable even though the dynamic handler code is rerunning.
My code is much more complex than this but I've created the simplest possible example to test it using an entity with just two fields.
My entity:
Code:
{ "fields": { "name": { "type": "varchar", "required": true, "pattern": "$noBadCharacters" }, "description": { "type": "text" }, "createdAt": { "type": "datetime", "readOnly": true }, "modifiedAt": { "type": "datetime", "readOnly": true }, "createdBy": { "type": "link", "readOnly": true, "view": "views/fields/user" }, "modifiedBy": { "type": "link", "readOnly": true, "view": "views/fields/user" }, "assignedUser": { "type": "link", "required": false, "view": "views/fields/assigned-user" }, "teams": { "type": "linkMultiple", "view": "views/fields/teams" }, "readOnly": { "type": "varchar", "maxLength": 150, "options": [], "isCustom": true } }, "links": { "createdBy": { "type": "belongsTo", "entity": "User" }, "modifiedBy": { "type": "belongsTo", "entity": "User" }, "assignedUser": { "type": "belongsTo", "entity": "User" }, "teams": { "type": "hasMany", "entity": "Team", "relationName": "entityTeam", "layoutRelationshipsDisabled": true } }, "collection": { "orderBy": "createdAt", "order": "desc" }, "indexes": { "name": { "columns": [ "name", "deleted" ] }, "assignedUser": { "columns": [ "assignedUserId", "deleted" ] }, "createdAt": { "columns": [ "createdAt" ] }, "createdAtId": { "unique": true, "columns": [ "createdAt", "id" ] } } }
Code:
{ "controller": "controllers/record", "boolFilterList": [ "onlyMy" ], "dynamicHandler": "custom:dynhand" }
Code:
define('custom:dynhand', ['dynamic-handler'], function (Dep) { return Dep.extend({ // called on initialization init: function () { console.log(`set read only`); this.recordView.setFieldReadOnly('readOnly'); console.log(`after set read only`); } }); });
Am I doing something wrong?
I am on version 7.5.5 of Espo.
Cheers,
Clare
Comment