Update a database field but sometimes

Hi! I’m having some issues with my app. It is designed to make specific calculations so everything is about numbers. But some calcs need to be done differently depending on the value given by the user and here is where my problems begin. The conditionals given by Adalo ar extremely limitated (for example, I cannot set an action to execute only if a certain database value is bigger or smaller than some number).
That’s why i’m using the arbitrary javascript snippet as I’m a developer. But it is extremely limitated as well. I cannot use it to make calculations with databaase values bigger than 1000 because everything breaks and most of my numbers are big numbers. I tried to make the snippet run only with smaller values (that would fix my problem right now, but maybe not in the future) but it will ALWAYS update the database value with a result, so I must set a new result including all the numbers (or it will return me an undefined), and that will break it when those values are bigger than 1000. I tried e v e r y t h i n g and lost several hours trying to make this work but there is always a situation where the code and/or the app will just explode.

Thank you so much!

Hi @Basset,

Is it possible to add a example of a calculation as a screenshot or a video and share your code here?

Thank you

Hi! I will try my best:
I have this form where the user must enter some values in order to get a cotization. But these values cannot be any number, they have minimums (gold 1gr/tm, silver 50gr/tm, copper 1%) or the formulas will throw a negative value, which is not appropiate as cotizations can’t ve negative.


What I need to do is some kind of conditional where if the contents are lower than those values, then the result must be 0. Sounds quite basic but I still can’t figure it out.

I tried the arbitrary javascript snippet, but if any of those values registered in the form is bigger than 1000, it will break. It’s like Adalo changes the type of data and it’s no longer a number. When I try to make comparisons between numbers and those database values, it just stops working. I tried parsing them but that does not work either.

I also tried to make something with the snippet like “do something but only if this value is lower than 50” but, as well, does not work. When the number is bigger than 50 it returns an undefined, and as it will always update the database, it ruins my results.
dads

Hope it’s more clear now. Thank you!

1 Like

Hi @Basset ,

Good job for describing the requirement in detail and with screenshots, this helps to find the solution.

There ia a video from Pragmaflow about custom form validation, if you can find them, it is a good explanation, what I did here is very similar and you can learn from both of these.

The cloneable app is here,
Custom Form Validation (adalo.com)

The reasons are because the input text is string and no trigger event at the input, so we need to save them in the collection first so we can compare them with numbers to validate and use button to do that, then we need to use visibility to enable the “Save” button.

The engine is not detail enough to perform such this validation and no local engine exists to help this either, so we need to use this workaround.

2 Likes

Thank you! I found the video of custom form validations, and I see you managed to make it work in your app. I am still investigating how did you do it, but will update you if I could replicate it!! (or not, hahaha)

Thanks Aldana for the explanation and thanks Yongki for your help here! And I’m sorry for this late reply!

Maybe adding the condition to the Arbitrary JavaScript component? And does the input is in Number type? Can I know what value you check with? Is it with a one input or a total of inputs?

Thank you

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.