dependent() on load of form

dependent() on load of form

simoncunsimoncun Posts: 16Questions: 5Answers: 0

Hi,

I've two dropdowns in an inline datatable, the second dropdown is dependent() on the first. This all works fine except for one thing. If I load the page and immediately click on the dependent dropdown it will be blank. If I click out and in again it's fine, the change event has fired and the options are populated. Is there a way to immediately populate the cell on table load? The data is being loaded from a database so the first dropdown already has a value. I know there's a change and keyup event in the documentation, is there a list of the other events? Is there any way of manually invoking the dependent listener?

Thanks.

Answers

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

    immediately click on the dependent dropdown it will be blank

    I would generally expect that to be the case since it won't have any information about the parent row's value. However, I suspect there is something I'm missing here - are you pre-populating a value into the first list? Are you able to give me a link to the page please?

    Is there any way of manually invoking the dependent listener?

    Two options:

    1. editor.field('myFieldName').input().trigger('change');
    2. editor.field('myFieldName').val( myNewValue );

    Regards,
    Allan

  • simoncunsimoncun Posts: 16Questions: 5Answers: 0

    Hi,

    Usual story Allan, internal development and no live link! The best I can do right now is a link to screenshots http://imgur.com/a/h2TTS

    Yes, I'm loading data from a database and pre-populating the first list. i.e. -

    Dropdown 1
    Option 1
    Option 2
    Option 3 (e.g. this is the selected option on pre-population)

    Dropdown 2
    if (dropdown1.option1)
    Option a
    Option b

    else if (dropdown1.option2)
    Option c
    Option d

    else if (dropdown1.option3)
    Option e
    Option f

    Dropdown 2 should also have an option chosen with a value coming from the database but right now nothing is displayed in the table for this, I assume because the dropdown hasn't had its options populated on table load.

    My plan was to somehow run my dependent() code on load of the table so it got the correct options and then selected the one from the database. With the two options you gave me, am I right in thinking that won't work on table load because the inputs don't exist at that stage?

  • simoncunsimoncun Posts: 16Questions: 5Answers: 0

    Sorry, ignore anything I said about the second dropdown not bringing values back, that was a bug in my code. The only thing that's not working is selecting the box on first click.

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

    With the two options you gave me, am I right in thinking that won't work on table load because the inputs don't exist at that stage?

    They exist immediately when the Editor has been created. I think either of the options above should trigger the dependent() action.

    Allan

This discussion has been closed.