Clear dependant field

Clear dependant field

ECEGROUPEECEGROUPE Posts: 79Questions: 30Answers: 1

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

  • rf1234rf1234 Posts: 3,086Questions: 90Answers: 427

    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()

  • allanallan Posts: 64,278Questions: 1Answers: 10,611 Site admin

    Is there a way to clear all the dependencies when initializing the editor?

    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

Sign In or Register to comment.