Page 1 of 2

Help I'm tearing my hair out - Updating database field

Posted: Sun Mar 02, 2014 4:56 am
by Sean McVeigh

I have a database with a single column ‘item’
In the application I have a page which displays this one ‘item’
I would like to have a text field in which the user can type an updated ‘item’
I would then like a button, which when clicked, updates ‘item’ with the text entered.

I have no idea of how to do this and been playing around with it for hours! Do I need to use a push service, local storage variable? I have no idea how to complete this simple task. If someone could take me through it step-by-step I would be eternally grateful!


Help I'm tearing my hair out - Updating database field

Posted: Sun Mar 02, 2014 5:07 am
by Alena Prykhodko

Hi Sean,

No worries&desperation :)
This doc shows how to update Database http://docs.appery.io/documentation/b...
You will need to use Database Service http://docs.appery.io/documentation/b... with settings as at the link above.

You can try some tutorials as well http://docs.appery.io/tutorials/build...


Help I'm tearing my hair out - Updating database field

Posted: Sun Mar 02, 2014 8:31 am
by Sean McVeigh

I've had a look over these, but I'm still lost! Would anyone be willing to list the steps involved? I just want to be able to update the one thing being stored in my database.


Help I'm tearing my hair out - Updating database field

Posted: Sun Mar 02, 2014 8:41 am
by Bad Addy

You wanting to populate the text box with the existing item first ?

And then the user would remove that text and update it ?


Help I'm tearing my hair out - Updating database field

Posted: Sun Mar 02, 2014 8:50 am
by Sean McVeigh

I have successfully managed to populate the text box on the screen with the existing item from the database. I have placed an input box and update button on the screen. I just want the user to be able to enter new data and press update. Thank you so much for helping out!


Help I'm tearing my hair out - Updating database field

Posted: Sun Mar 02, 2014 9:06 am
by Bad Addy

Okay, so you need to use the update collection Service, and invoke it on the on the button clicked.

So create a new database service and pick update service on the collection name. When the item is returned, you need to capture the _id and put it in localStorage or a label thats not visible.

using the _id, you use the service and in the URL you need to add {id} at the end.

precode
https:&#47;&#47;api&#46;appery&#46;io/rest/1/db/collections/<collectionName>/{id}
/code/pre

In the request tab of the service, add 'id', and map the _id that you just stored to the value of id. Now it knows what object (row) it needs to update.

Then you need to add another request param 'item', and then map the populated edited text box to it.

Thats it! When the user visits that page, with the 'item' in the text box, it stores the _id. When the user changes the text and clicks the button, it invokes the service, uses the _id, and updates that col 'item' in the correct row.

Let me know if that helps and if you have success :)

Note: If you have more than one 'item' its best to use listview, and place a invisible label and populate the _id in that, so you know what each _id belongs too.


Help I'm tearing my hair out - Updating database field

Posted: Sun Mar 02, 2014 10:16 am
by Sean McVeigh

Thanks for your guidance. I'm getting there slowly - when I test the update service it is successful.


Help I'm tearing my hair out - Updating database field

Posted: Sun Mar 02, 2014 10:35 am
by Sean McVeigh

I'm getting there - I can update the database using the update service (test). Just can't get the text input to update my database when the button is pressed!


Help I'm tearing my hair out - Updating database field

Posted: Sun Mar 02, 2014 10:39 am
by Sean McVeigh

Fantastic! got it working - thank you so much (Bad Addy & Alena), you can't imagine how much I appreciate your help.


Help I'm tearing my hair out - Updating database field

Posted: Fri Nov 07, 2014 6:11 pm
by Cj Bernauer

Can you do this with multiple items in the data base?
Like changed all the stored values in a certain column in the database to something by clicking one button?

Like lets say I have columns identifying what data I'm collecting, and a column called "draft". Is there a way that you can update everything in the database in that column with one click?