Easy way to compare detect if values have changed

The context is for the purpose of detecting when someone has made changes to some piece of information (like account information). I use this to enable/disable the save button, show tooltips etc.

The idea is to use the :minus list operator against 2 text lists. One list the saved values, the second list will be current input’s values. If the count is more than 0 then it means that there has been a change. You can use Arbitrary texts:split by() to create the text lists.

Example:

I’ve tried many methods like setting states and stuff but this takes is the simplest and tidiest way to do it natively IMO. The lists do not have to be in the same order since :minus list doesn’t take that into account. You can insert the expression into a group as a yes/no value and refer to that group’s value if you want to use it in other conditions. Now you only need to manage 1 expression instead of multiple.

14 Likes

Wow, that’s a great tip. Thank you!

1 Like

One downside I guess is this wouldn’t work with checkboxes

What you could do is use :format as textand give it a unique text for yes and no. Do the same for both the checkbox and the saved yes/no value.

Oh yeah, good point

This is super helpful - far better than what I am currently doing! Thanks for sharing!

1 Like

Just tested this handy tip… my future goto for sure - thanks for sharing,

1 Like

can you share an editor link for this implementation

you can look at my test site if you like, https://sandy-box.bubbleapps.io/version-test/app/users ← user/pass
editor for a reusable where this is used: Sandy-box | Bubble Editor

image

I use this for some testing, so it may go away at some point…
I use this as a function to then send a javascript yes/no to another resuable to enable the submit button incase you wondering what this does in my case.

1 Like

Thanks Stuart.

1 Like

This gave me another idea that works quite well… which I thought i would add here.

if you wanted to do a pre validation on if fields are “not empty” before you make a save button active.

you could do a somthing similar, but without the lists and could if the fields you would like to be mandatory are not empty.

In this example I have 7 fields, I want them all to be used before they submit - so i just check them all and update the group.

Note: you can’t use ‘is valid’ as a condition, because this only checks when the inputs actually got a value to check IF its valid against how youve set the field entry (number, text, email, shouldnt be empty etc).

image

1 Like

Thanks for bringing it up. There is that weird issue where blank fields will cause false positives. I’ve actually made a plugin for myself to make things easier.

TCH - Compare Lists Plugin | Bubble

Works the same way as you would in this thread but it’s handled by a simple JS script. Makes expressions implementation and revision easier. Hope it helps!

Disclaimer, I’m new to Bubble plugin building and I use AI to help me script cause I hate writing code.

3 Likes

nice - ill check it out!