Editor dependent is causing an infinite loop, when I try to setup field change based on the data

Editor dependent is causing an infinite loop, when I try to setup field change based on the data

DeusoqDeusoq Posts: 1Questions: 1Answers: 0

So I got a dropdown Status, which no options in them. Because I want the following based on the column data it fills up.

Ex: if Status is "Active" then I "Active", and "Inactive", If its "Inactive", then "Inactive", "Reactive", and if its "Reactive", I need "Inactive", "Reactive".

 {
     label: 'Status',
     name: 'Status',
     type: 'select',
     options: []
 }

Dependent but runs in infinity loop.

Code:

editor.dependent('Status', function (val, data, callback) {

    let options = [];

    if (data.row.Status === "Inactive") {
        console.log('changing options: 1')
        editor.field('Status').update(['Inactive', 'Reactive'])
    } else if (data.row.Status === "Active") {
        console.log('Changing 2')
        editor.field('Status').update(['Inactive', 'Reactive'])
    } else if (data.row.Status === "Reactive") {
        console.log('Changing 3')
        editor.field('Status').update(['Inactive', 'Reactive'])
    }
}

Answers

  • rf1234rf1234 Posts: 3,066Questions: 89Answers: 427

    Updating the options seems to trigger change. Hence you should only update the options when they have changed. Then the infinite loop should end.

Sign In or Register to comment.