Page 1 of 3

Challenges with Select component - values change back to 1st value in list

Posted: Thu Nov 13, 2014 7:58 am
by Bruce Stuart

Happy Thursday...

I have a control on a UI that I'm using a list of values - selected by the user in a Select component.

during selection and then reading from the control and placing values in the db the control works fine.

However, when I read the data from the db - move the contents from an array - and then values into my select components.... in the data read service.successs method I place data in the control - and then log it back to the console. the value on the control is correct.

the next event to occur is page show - and I have no code manipulating the values of these select components - and much to my dismay - all of them have reverted backi to having the value of the first item in the list (despite the fact that I logged the value immediately prior to page show and it was correct....).

here's the output from my log of the value on the control versus what was in the db - and
Color value for tee:1is:#e9ed11 versus:#e9ed11 VM231687:675
Color value for tee:2is:#a8a82f versus:#a8a82f VM231687:675
Color value for tee:3is:#78786d versus:#78786d VM231687:675
Color value for tee:4is:#121111 versus:#121111 VM231687:675

followed by my completed event for the read:
golf course read complete & successful VM231687:612

followed by logs of the values of the same 4 controls milliseconds later in the page show even... and you can see all of the data values have changed on the controls:

Tee 1 color :#d41140 VM231687:811
Tee 2 color :#d41140 VM231687:812
Tee 3 color #d41140 VM231687:813
Tee 4 color :#d41140

I tried turning off 'data reading' which is done by the select control at startup per the Jquery docs for these controls by issuing this command....but I don't really understand if this is the issue or not.:

Appery( scontrolname ).selectmenu( "option", "defaults", true );

(this should cause the control to ignore the default code to attempt on startup to read from the data - and just still with the default - current value assigned to it....
but there is no effect.

Anyone have any experience here - I could sure use the help. This is somewhat frustrating...


Challenges with Select component - values change back to 1st value in list

Posted: Thu Nov 13, 2014 9:20 am
by Maryna Brodina

Hello!

Sorry, could you clarify if you want to leave selected element as selected after service invocation or remove selection?


Challenges with Select component - values change back to 1st value in list

Posted: Thu Nov 13, 2014 2:20 pm
by Bruce Stuart

Hi Maryna

Thanks.... After reading the values from my db, and placing the values in my selectmenu's ...I want the values to stay as they were when I read them from the db.

The issue is the framework pageshow() or pageload() event seems to clear these values for the selectmenu() components in a way that is unlike any other control.

All other controls hold their assigned values after having values assigned....selectmenu component does not hold the assigned value.... But perhaps I'm missing something or have not followed some piece of documentation correctly.

Best,
Bruce


Challenges with Select component - values change back to 1st value in list

Posted: Thu Nov 13, 2014 7:12 pm
by Andrew Davidsburg

Also having similar problems with my app since the upgrade to the new system. I can't seem to find any reason for this to happen. FYI it is also hapening after I fire a rest service based on a change to an input. Any help would great!

Thanks!

Andrew


Challenges with Select component - values change back to 1st value in list

Posted: Thu Nov 13, 2014 8:13 pm
by Bruce Stuart

Andrew, I have a hack that I developed tonwork around the issue ... Want some sample code ? It's not a fix for what I think is a defect ... But it makes my app work and appear to the user as if the issue did not exist ...

Let me know and I'll post my sample ( which is the same issue you explain I think ) zzz

Best, Bruce


Challenges with Select component - values change back to 1st value in list

Posted: Thu Nov 13, 2014 8:21 pm
by Andrew Davidsburg

Thanks bruce, yeah that would be great! I've gotten it switch back after load, but now the resetting after the firing is where I'm stuck.


Challenges with Select component - values change back to 1st value in list

Posted: Thu Nov 13, 2014 9:33 pm
by Bruce Stuart

Well ... Let me tell you about my solution and see if it's like yours ( till I get back to my desk in an hour when I'll send the code ).

In my data rest service .. For my selectmenus ... I spin the values that were set by the data service ( in the success method ) into an array. I then use json stringify to save the array to a invisible control on my page ( could easily be a local storage var as well ) ... I also set a Boolean value I called 'bselectmenusneedfixong' to true. In my pageahow method or anywhere after I refresh the data I check for the Boolean ... If true I json parse my saved data back into array form, and move the values to the selected values in the selectmenus ... And of course set my Boolean local storage var to false ...


Challenges with Select component - values change back to 1st value in list

Posted: Thu Nov 13, 2014 9:38 pm
by Bruce Stuart

Should be 'pageshow' method above :-)


Challenges with Select component - values change back to 1st value in list

Posted: Thu Nov 13, 2014 9:56 pm
by Andrew Davidsburg

Thanks a lot Bruce, I think that solution would just for for the initial load correct?


Challenges with Select component - values change back to 1st value in list

Posted: Thu Nov 13, 2014 10:48 pm
by Bruce Stuart

Andrew,

Probably not the best answer - but - maybe yes - maybe no (know lol).

A couple of things to consider:

  1. Be surprised on how often the pageshow event occurs (you probably already know....but...). I found out by sticking a console.log event in there as a part of trying to fix this issue. I found that simply by clicking on a selectmenu - and then when I return - pageshow fires. Creat a popup - and what fires when the popup goes away - pageshow.

  2. Although the world of app development works asynchronously (ok bad spelling - but I'm typing here lol) ... there are ways of waiting for something to occur. In your case - there has to be something that triggers the need to re-fire getting data from your data source - in that event - hang out in your javscript right after you fire that event (the get data again event) with a famous 'set-timeout' method - where - in your wait clause - you wait for the boolean I referred to above - to go to 'TRUE' (so do while !boolean ).... when you pop out of the loop - you know the data has been refreshed - and its ready to load to your controls - so read the vars from local storage or the invisible control - refresh your selectmenu's one at a time with Apperyio( scontrolname ).refresh() ; - and you could be good to go.(emphasis on could...)

    I'm probably oversimplying things - so - help me understand more :-)

    Best,

    Bruce