Page 1 of 3

How to update input text box with value from database

Posted: Tue May 06, 2014 8:31 pm
by Deki

Hi,
I have a problem with input text boxes saving the user input in between pages and not displaying data from the database. My workflow is the following

1) user Alvin logs in and navigates to a screen with an input box called 'weight'
2) user Alvin enters in weight and clicks a save button
3) the value is saved in database
4) user Alvin logs out
5) user Jon logs in
6) Jon goes to the screen to input his 'weight' and rather than getting his weight from database and displaying it in the input box 'weight', it has the same value that the previous user (alvin) put in.

How can I avoid this problem of the input box saving its value in between user sessions? Thanks


How to update input text box with value from database

Posted: Tue May 06, 2014 9:09 pm
by Kateryna Grynko

Hi,

Are there any console errors for user Jon?


How to update input text box with value from database

Posted: Tue May 06, 2014 10:14 pm
by Deki

Hi,
No, there are no console errors. It's just that when I modify the text inside the 'input box', that same text remains until I manually change it again. Basically what I am trying to do is read data from database and be able to update that data all inside an input box...no other fields.

A) read data/value from database (for user logged in) and display it in 'input box'
B) logged in user has ability to modify this data by changing value in 'input box' and clicking update button

The problem occurs when I modify the value inside the input box. That same value remains all throughout the use of the application, no matter if I specify in the List Service to update the field from the database. If you see the screenshot below, I point the weight to the input box for weight. However, this does not work if I manually modify the input box and click update. If I do that, the value is not read from database anymore, but from whatever I entered in manually.

Image Image


How to update input text box with value from database

Posted: Wed May 07, 2014 6:07 am
by Evgene Karachevtsev

Hello Deki,

You should somehow differentiate your weight records in DB collection. It means that each record should have an id of the owner. This id you should pass into request parameter.


How to update input text box with value from database

Posted: Wed May 07, 2014 12:24 pm
by Deki

Yes, each record does have an id of the owner.

I think it would be easier if you can show me an example? Can you please do that? I am just trying to update and read a database field from the same input box. If you can show me an example of how to do that, that would be fantastic. Just one input box - that can both read and write/update the same field in the database. Thanks a lot.


How to update input text box with value from database

Posted: Wed May 07, 2014 1:47 pm
by Evgene Karachevtsev

Hi, Deki

You should invoke read service on "page show" event and update service on "value change" event for this input component.
http://docs.appery.io/documentation/b...
http://docs.appery.io/documentation/b...


How to update input text box with value from database

Posted: Wed May 07, 2014 1:58 pm
by Deki

Can you please clarify what you mean by "update service on 'value change' event"? How can I do that? Thanks


How to update input text box with value from database

Posted: Wed May 07, 2014 2:16 pm
by Kateryna Grynko

Hi,

You have an input field "weight", "value change" event fires when it's value is changed. On this event invoke an update service and rewrite new value from this input into your DB record.


How to update input text box with value from database

Posted: Wed May 07, 2014 2:44 pm
by Deki

I have done that and it works fine. I’ve put in a change event that saves data to database. So, once the value is changed, it saves it correctly in the database. However, that is not the problem. The problem is that once I change the value in the input – that value remains constant even if the user logs out and another user logs in. I don’t understand why the list/read service does not update the value inside the input box if the value changes. The list/read service only updates it if I do not change anything in the input box. That’s really the problem. I have tried clearing out the input boxes on logout service like this - Appery('inp_weight').val('');. However, when the next user logs in, they remain empty, even though I have the read service on Page Show. No data is read into the input box.


How to update input text box with value from database

Posted: Wed May 07, 2014 9:11 pm
by Kateryna Grynko

Hi,

On what request do you invoke service that writes values?
Are there any errors when it doesn't clear results?
Could you please clear input fields before invoking this service?preApperyio('inp_weight').val('');/pre