Is there a more graceful way to enable/disable fields based on create/edit actions?
Is there a more graceful way to enable/disable fields based on create/edit actions?
Based on information in the forums, I am presently doing this sort of thing:
editFields = ["stock_num", "avg_cost", "uom"];
editor.on( 'initEdit', function () {
for (var i=0; i<editFields.length; i++) {
editor.disable(editFields[i]);
}
} );
editor.on( 'initCreate', function () {
for (var i=0; i<editFields.length; i++) {
editor.enable(editFields[i]);
}
} );
Is there a more graceful way to accomplish this?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You don't need the loop -
disable()
andenable()
will accept arrays:is about the most graceful way I can think of.
Allan
Ahh... nice. And chaining++
The only other trick I've got to clean it up a bit more is to use arrow functions from ES6:
But you would need to use a cross compiler such as Babel JS to have it work in most current browsers...!
Ultimately perhaps Editor itself should have something like the
dependent()
method... (thinking on the keyboard... :-) ).Allan
That sounds like a very good idea.
Chris