Clear dependant field
Clear dependant field
Hello,
I have two tables (we'll call them Table 1 and Table 2), both set up with an editor, but only Table 1 uses the dependent editor setup. The setup for Table 1 looks like this:
editor.dependent('COLUMN-TEST1-TABLE1', function (val) {
if (editor.get('COLUMN-TEST2-TABLE1') == 2) {
return { values: {'COLUMN-TEST1-TABLE1': "12"} };
} else if (editor.get('COLUMN-TEST3-TABLE1') == 2) {
return { values: {'COLUMN-TEST1-TABLE1': "11"} };
}
});
This works perfectly to set a column's value based on the value of another column when submitting data.
The problem arises when I load another table to replace the first one. I get an error: Unknown field name - COLUMN-TEST2-TABLE1
. This happens because Table 2 has different columns and data.
Is there a way to clear all the dependencies when initializing the editor?
Thanks in advance for your help!
Answers
If you have different tables with different columns you should also have different editors with different "dependent" methods.
In that case you shouldn't have any issues.
You can use "destroy" to destroy an Editor. And "undependent" to clear existing dependencies.
https://editor.datatables.net/reference/api/destroy()
https://editor.datatables.net/reference/api/undependent()
There shouldn't be any dependencies on a field when it is initialised. As @rf1234 says,
undependent()
is how to remove a dependent listener, but there shouldn't be one when just creating a new instance.It sounds like you might be destroying one instance and creating another? Can you give me a link to a test case showing the issue please?
Allan