Page 1 of 1

Hiding/Showing button as per favouriting item

Posted: Mon Mar 16, 2015 10:26 pm
by Sunita

Hi,

I have a page where I have a button to add an item as a favourite, and the same page has a button to delete that item from the favourite list.

However, I just want one button on this screen. I want that add button to change to delete button only for those items that have been added as favourites.

How can I do this? Please help.

Many thanks.


Hiding/Showing button as per favouriting item

Posted: Tue Mar 17, 2015 12:56 pm
by Egor Kotov6832188

Hello Sunita,

I assume you receive your items from DB
1) Create LocalStorage Variable in Model&Storage based on your item structure.
2) Add extra field and name it favorite and type Boolean with default value False
3) Map response from DB to this LSV
4) on add to favorite click find element in LSV and change favorite field to true


Hiding/Showing button as per favouriting item

Posted: Tue Mar 17, 2015 2:20 pm
by Sunita

Hi Egor,

Thank you for you reply.

I let users add items as their favourites. So every user (with userID) has a different set of favourites (vegID) in the DB. So an item that one user has, might not be present in other users favourites.

How can I make sure that button changes to "delete" only for a particular user as per a particular item?


Hiding/Showing button as per favouriting item

Posted: Wed Mar 18, 2015 11:14 am
by Sunita

Any help will let me get on with my app. Please provide some suggestions?


Hiding/Showing button as per favouriting item

Posted: Thu Mar 19, 2015 4:28 am
by Yurii Orishchuk

Hi Sunita,

Please show us more info about your implementation and what you want to implement.

Regards.


Hiding/Showing button as per favouriting item

Posted: Mon Mar 23, 2015 7:52 pm
by Sunita

Hi Yurii,

Sorry about the late reply.

So I have a page where a user can add the vegetable as their favourite by clicking on '+My Veg'.

http://prntscr.com/6kgyaj

On the same page, you can see a delete button too which is '- Delete from My Veg'.

However, I just want one button instead of these two. So when I click on it, it changes its value. For example, if it says '+My Veg', and I click on it, it should add the vegetable to favourites for that particular user and change the value of that button to '-Delete from My Veg'.


Hiding/Showing button as per favouriting item

Posted: Tue Mar 24, 2015 10:10 am
by Sunita

Hi there,

Any updates please? This is quite urgent with my work.


Hiding/Showing button as per favouriting item

Posted: Wed Mar 25, 2015 5:46 am
by Yurii Orishchuk

Hi Sunita,

Here is a best way to do it:

  1. Add "Add to my Veg" button after "Delete from my Veg".
    Details: http://prntscr.com/6l25tn/direct

  2. Now you can manage visibility of these two in accordance to you logic:

    You can use following code to show/hide buttons:

    pre

    //This line of code will show the button.
    Apperyio("buttonName").show();

    //This line of code will hide the button.
    Apperyio("buttonName").hide();

    /pre

    Regards.


Hiding/Showing button as per favouriting item

Posted: Wed Mar 25, 2015 12:00 pm
by Sunita

Hi Yuuri,

Thank you for your response.

I have tried what you have suggested almost a month back, but it just hides both the buttons.

The app logic is - a userID is captured along with the vegetableID when it is added by this user to his favourites.

How can I check for this to show/hide buttons?


Hiding/Showing button as per favouriting item

Posted: Fri Mar 27, 2015 1:05 am
by Yurii Orishchuk

Hi Sunita,

we don't know how you organized your favorites thus we can not tell you about condition.

But in common way you should have following js code:

pre

if(.....condition to define if current item is already in favorites... ){
//Case if item is in favorites at this time.
Apperyio("addToFavoritesButtonName").show();
Apperyio("removeFromFavoritesButtonName").hide();

}
else{
//Case if item is not in favorites at this time.
Apperyio("addToFavoritesButtonName").show();
Apperyio("removeFromFavoritesButtonName").hide();
}

/pre

Regards.