I have an Editor form with a.o. fields for alternative delivery address. If the "montering_alt" field is "1" there is also a "montering_adr" so I want to hide the fields if the first field is not "1". I also want the same for the field "reg_std" , show it only if its value is "1".
editor = new $.fn.dataTable.Editor( { ...........
fields: [
{
label: "Alt. monteringsadr.",
name: "montering_alt",
type: "hidden"
}, {
label: "Monteringsadresse",
name: "montering_adr"
}, {
label: "Standard montering:",
name: "reg_std",
type: "radio",
options: [
{ label: "Nei", value: 0 },
{ label: "Ja", value: 1 }
],
def: 0
}
]
Function to check when editing to hide the fields if they are not "1"
editor.on( 'initEdit', function () {
if (editor.val( 'reg_std' ) != 1) {editor.hide( 'reg_std' );}
mont_alt = editor.val( 'montering_alt' );
if(mont_alt != 1)
{
editor.hide( 'montering_adr' );
editor.hide( 'montering_postnr' );
}
} );
The problem is that the first time I click on a row, the logic works. I can log to console and the value is "1". I see the field "montering_adr". The next row does not have value "1" so the field is hidden. After clicking several records I go back to the first record and the field "montering_adr" is hidden now. But in console the value is "1" (it should show). I tried to redraw the table after each edit but the conditional does not kick in before I refresh the page again. Anyone see why the conditional does not work after at time?