PricingBlog

Add and remove product tags/ add to or remove from array

  • needtheanswers-1279508360713994250

    needtheanswers

    1 year ago

    Lets say I have a xano db table for products and another one for tags. One field in the products table includes a list of table references to the tags table. On default the list for tags in the products table is empty.

    In Toddle I have a form to add a new product and the form includes all the available tags that are rendered based on my get_tags api. Each tag has an id, a name and a boolean called 'added' that is always false (just to make it easier for myself). On change (I use checkboxes with labels) I want to add the tag and when I uncheck I want to remove it. Obviously I don´t want to add or remove any tag if the product form is not completely filled out (name, description, etc) because the product is gets created on form submit.
    How would you go about this?

    My approach was:
    1) create a variable called tags_array which is just an empty array
    2) render the checkboxes based on the api and also set the value based on the api
    3) try (emphasis on try!) to and or remove the tags_id based on the value of the checkbox.

    The problem is that my formula adds tags but doesn´t remove them when I uncheck the checkbox. How can I solve this or has anyone a better approach?

    Thanks
    1279508360957394975-image.png
    1
  • needtheanswers-1279519967985008770

    needtheanswers

    1 year ago

    I also tried doing this on the change event but this only seems to work when I refresh the page. After doing this a few times in just stops adding or removing ids.
    1279519967615914094-image.png
  • needtheanswers-1279529686392766518

    needtheanswers

    1 year ago

    I found this post and it seems for work fine for my use case https://discord.com/channels/972416966683926538/1130812696070193152
  • needtheanswers-1279530068065915066

    needtheanswers

    1 year ago

    1279530067877429268-image.png