Editor .dependent() and multi-row editting.

Editor .dependent() and multi-row editting.

HassanDomeDeneaHassanDomeDenea Posts: 29Questions: 10Answers: 0

Greetings.
The simple dependent example can use a json like this to update the field (item_price) value:

return {
    values: {
        "item_price": "100"
    }
}

let's suppose we have selected two rows for editting.
What json can I supply for the dependent function to set distinct value for each record ? for suggestion to edit the records of id 5 and 6:

return {
    values: {
        "item_price": {
            "5":"100",
            "6" "125",
        }
    }
}

The above example doesn't work. So how to use this correctly if it was possible ?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 51,440Questions: 1Answers: 7,758 Site admin
    Answer ✓

    Currently I'm afraid it isn't possible. At this time the values object that dependent() accepts is singular (i.e. one value for all field's being edited).

    To work around that you'd need to add an input / change event to the input element you want to listen for changes from and then use field().multiSet() once the values have been retrieved from Ajax (i.e. basically the same as dependent() does, but with a little extra processing for the multi-rows).

    Allan

  • HassanDomeDeneaHassanDomeDenea Posts: 29Questions: 10Answers: 0

    I see.
    I also put a simple workaround, by checking the length of the (rows) array, and skipping the dependent function entirely if they were more than 1. (Which satisfied my needs), because I don't want to edit them anyway.

    editor.dependent('supplier_id', (val, params, callback) => {
                                axios.post('link/supplier_id_dependent.php', params)
                                    .then(({data}) => {
    
                                        let  supplier = data.supplier;                                                                                                            
                                        let response = {
                                            values: params.rows.length < 2 ? { //Do The Changes
                                                'supplier.name': supplier.name || '',
                                                'supplier.phone': supplier.phone || '',
                                                'supplier.address': supplier.address || '',
                                                'supplier.key_id': supplier.key_id || '',
                                            } :
                                            { }, //Do nothing                                    
                                        };
                                        callback(response)
                                    })
                            });
    

    If someone desired to edit them (to single value), maybe he can check if all the records of the (rows) array having that field are equal (which meanse, single value at the end).

Sign In or Register to comment.