Disable field based on row
Disable field based on row
Hi,
i have an editor working, but for some rows it should not be possible to update a certain field.
so i wanted to disable the fields if a certain data attribute is set.
how should we do this?
i was looking at the preCreate event, but i'm not sure if its possible from within an event
Maikel
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
It is also possible from within an event but it doesn't seem to be required, right?
If you use "dependent" from within an event you should make sure to use "undependent" on close of the Editor to avoid having the "otherField" in a state that you don't want for other events, e.g. editing a record as opposed to creating it.
e.g.
its not dependence between 2 fields, its dependency between external data and a field.
The external data is in data-attributes on the row html tag
I would make the data attribute a hidden field in Editor. Makes it a lot easier.
but this data is different for every row ...
What does it look like? You can't transform it into a value range of one attribute? Like the attribute “color“ with value range green, blue, yellow, red, brown etc. different for every row of the table.
What is the rule to decide whether or not the other field should be disabled? Can you post your use case?
use-case
i have a table that defined in dom with about 20 columns, most are static columns but 5 or them are changeable by a user.
1 column can only be changed if certain data is set for this row (i can still define where the data will be placed)
so defining this data in the editor is not an option as this is row specific enable/disable
Don't understand it. All values in Editor are row specific. Why do you think this is special? Cannot help you based on this. Sorry.
my table looks like:
http://live.datatables.net/bohunafu/2/edit?html,js,console,output
if data-enabled=yes (on the row) i want to enabled one field in the editor, if data-enabled=no then that field should be disabled
if you must use data-attributes please take a look at this.
https://editor.datatables.net/manual/templates#Inserting-fields
I guess you will need to make changes if you want to have this in Editor.
Alternatively you could just loop through the dom table and create a hidden td for each tr containing the "enable" / "disable" or whatever you require with jQuery and subsequently initialize the data table and editor.
Your example has a script error and no Editor instance unfortunately.
i used the last sugestion, and got it working