Results 1 to 5 of 5
  1.    #1  
    I've been able to sucessfully create a listSelector, however, I want to be able to dynamically change the choices that are available.

    I change the choices array, but it doesn't update the listSelector. How do I force a update if the choices array changes?

    this.bookList = someArray;
    this.controller.setupWidget('bookSelector', {label: $L('Book'), choices: this.bookList, modelProperty: 'currentBook'}, this.bookSelectorsModel);

    //now if I change this.bookList
    this.bookList = someOtherArray;
    // How do I get listSelector to update???

    Thanks in advance!
  2.    #2  
    Okay, so I figured this out and thought I'd share in case anyone else was wondering...

    The key seems to be that you can set the "choices" array in two possible places:
    1) The attribute array's choices field
    2) The model's choices field

    Previously I was setting the choices via the attribute array, however I was not able to find anything to trigger changes on attributes. But, I was able to find the controller.modelChanged function that updates all widgets that are using the specified model.

    The solution for me then was to define the choices via the model's choices field, rather than the attribute array.

    My solution looked something like this:
    this.bookSelectorsModel.choices = this.bookList;
    this.controller.setupWidget('bookSelector', {label: $L('Book'), modelProperty: 'currentBook'}, this.bookSelectorsModel);

    //now if I change this.bookList
    this.bookSelectorsModel.choices = this.someOtherBookList
    // The line below triggers the updates to the listSelector
    this.controller.modelChanged(this.bookSelectorsModel);

    Hope this helps someone!
  3. #3  
    I have tried that before. I was able to change the list selector, but default values were never reset. Does that reset the default value as well?
  4.    #4  
    I was able to get it to reset the default value as well, but not w/ the code I listed above.

    Basically to reset the default, you also need to change the (in my example), "currentBook" field of the model.

    Like this:
    //now if I change this.bookList
    this.bookSelectorsModel.choices = this.someOtherBookList
    this.bookSelectorsModel.currentBook = "my_new_default"
    // The line below triggers the updates to the listSelector
    this.controller.modelChanged(this.bookSelectorsModel);

    Hope this helps!
  5. #5  
    Quote Originally Posted by etarina View Post
    Okay, so I figured this out and thought I'd share in case anyone else was wondering...

    The key seems to be that you can set the "choices" array in two possible places:
    1) The attribute array's choices field
    2) The model's choices field

    Previously I was setting the choices via the attribute array, however I was not able to find anything to trigger changes on attributes. But, I was able to find the controller.modelChanged function that updates all widgets that are using the specified model.

    The solution for me then was to define the choices via the model's choices field, rather than the attribute array.

    My solution looked something like this:
    this.bookSelectorsModel.choices = this.bookList;
    this.controller.setupWidget('bookSelector', {label: $L('Book'), modelProperty: 'currentBook'}, this.bookSelectorsModel);

    //now if I change this.bookList
    this.bookSelectorsModel.choices = this.someOtherBookList
    // The line below triggers the updates to the listSelector
    this.controller.modelChanged(this.bookSelectorsModel);

    Hope this helps someone!
    Thanks so much for this. I've been staring at my screen for hours trying to figure this out. I kept on trying to set the model like this (using your example):

    this.bookSelectorsModel = {choices: this.someOtherBookList}

    and it wouldn't take after using modelChanged. Whew, now I can finally move on with my life. =)

    uptempo777

Posting Permissions