Load Dropdown based on row

Load Dropdown based on row

GG Posts: 16Questions: 7Answers: 0

Hello Allan

Absolutely stuck at this point. Your help will be truly appreciated.

We have a requirement whereby, we click on the row to edit it, which brings up edit modal... all gr8.
So, in our edit form we have multiple fields. One of them is a dropdown, used for "STATUS"

Till now we were filling in the dropdown with one set of values. However, now we need to show different values / text based on the row selected.

For eg: If you select row 1: the user can only set the status to "delivered", "Cancel delivery"
but when you select row 2: the user can only set the status to "reorder order", "Cancel subscription", "delivered", "Cancel delivery"

So, basically We want to supply different "inOpts" to the editor based on the row clicked.

Currently the code i am using is

editobj = {
"label": lbl + ":",
"fieldInfo": "" + lblinfo + "",
"name": "" + lblname + "",
"dataProp": localnumdata[i],
"ipOpts": {}
"type": "select"
}

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Hi,

    This sounds like a perfect use case for the dependent() method. With that you can apply a condition to a field and specify the options you want the second field to have when the parent changes.

    Allan

  • GG Posts: 16Questions: 7Answers: 0

    so, dependent would be fine if we were updating a choice (like radio) in the editor panel.

    However, I am looking to fill the dropdownlist in the editor using ipOpts, depending on a column value of the editing row. On editor load.

    Allan pls provide me a code snippet to understand.

    Thank you.

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    It still sounds like dependent() would be ideal, be it for radio inputs for select inputs (in fact, it makes no difference which of those two fields types are being used, the code would be identical).

    Alternatively, if you don't want to use dependent(), you could use the select field type's update() method - editor.field( 'myField' ).update( ...options... ); whenever you want to set the value of the options.

    Allan

  • GG Posts: 16Questions: 7Answers: 0

    Please can you elaborate the syntax

    editor.field( 'myField' ).update( ...options... );

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    There is an example in the select documentation. To explain it further, the myField is the field name for the field you want to modify (just as you can do editor.field('myField').val() to get the field's value). The ...options... is your list of options - probably an array of objects.

    For example:

    editor.field('rank').update( [
       { value: 1, label: 'First' },
       { value: 2, label: 'Second' )
    ] );
    

    Allan

This discussion has been closed.