Modifying an editor based on user context and editor mode
Modifying an editor based on user context and editor mode
We define an editor and its fields with the full functionality by default.
In our context a logged in user has a particular role and should be able to see or use a subset of the form based on its role and the editor mode (edit, new, delete).
A typical case is to change some writable fields to readonly or hide them. The role is given in JS through a variable.
So what would be the best approach to change an editor instance and its field definition before each edit/new/search invocation based some code for implementing the necessary changes to the field definition?
Answers
The way I would implement this myself would be to serve different Javascript to different users based on their access role. Moreover, I would usually dynamically build the Javascript (like like you can with HTML) based on the access role.
A simpler method is just to include the access information in the Javascript as a variable and code branch on that - but it would be trivial for someone to change that variable and thus elevate their access rights (although of course the server should be doing access right checking on write as well).
Allan
Serving different editor models by role should not be a problem.
However the model for a particular user or role might be different in edit mode from create mode.
So would it be possible to define different forms for different editor modes?
Would it be possible to create two editor instances - one for "new" and one for "edit" mode with two different field settings and associate with table?.
I see in this example
https://editor.datatables.net/examples/api/triggerButton.html
that it is possible to associate an editor button with a dedicated editor instance using the
editor
option.Would this make sense?
I verified my approach and it is actually working..
Yes - that would be the correct way of doing it. Nice one.
Allan