Hi,
When checking for empty fields on forms for text I can do something like this....
variablename.name <> ""
This doesn't work for a number as it's not a string, obviously but I can't check for null either as OutSystems seems to populate empty integer fields with a 0.
How do devs work around this when working on form validation as sometime 0 is a valid entry.
Thanks
So for your case if 0 is a valid entry sometime then there is not any logic to check if its valid or not. As default value of integer is also 0. So will not be able to identify that this 0 is entered by user or not until don't use any event listener or key press events.
Easiest approach may be to use some value as default value (like negative values) which not suppose to be enter by user in any situation. Then on form validation you can check for this value. But in this case also you need to handling of this otherwise it will store garbage value in database.
regards
Hi @Vikas Sharma
Thank you for your reply this is a good approach.
When I specify a default value myself in my structure/variable. This is displayed in the form field.
Do you know of an easy way to handle this or is the only option to use a conditional style class to colour the text white if the value is -1 for example.
Seems like a bit of a fudge and there are also some specificity issues which arise as I'm targeting a value inside of an input field which inherits from Outsystems UI.
Any suggestions?
You can disable to show the default value. In attributes put show-default-value as false. As mentioned in this post by @Nuno Reis
https://www.outsystems.com/forums/discussion/83220/i-wanted-to-know-how-to-bind-0-zero/
This doesn't seem to work for me? The attribute is in the HTML when I inspect it but it has no effect?
Hy @JayPea
You can change the variable to text and validate it in the submit action.
Then to prevent the user to put only numbers:
https://www.outsystems.com/forums/discussion/78790/allow-user-only-put-numbers-on-input-widget/
https://www.outsystems.com/forums/discussion/43966/numeric-keyboard-that-allows-only-0-9/
Hello @JayPea,
On Submit action you can convert integer to text and then compare with empty string in if condition
e.g.
IntegerToText(GetProjectDetailById.List.Current.Price) <> ""
Prajakta Roshankhede
Thanks @Prajakta Roshankhede
I do like this approach not sure if it will work though as it might just end up with a string of "0"?
Going to try and implement it.
John
This didn't seem to work as solution as it wasn't viewed as an empty string.
This worked for me
I used this to check if the integer is actually empty (as in "null").
NumberVariable <> TextToInteger("")
It was actually more of a design consideration in the end. I used radio buttons to determine if certain fields were optional and then I could validate the input with is X > 0.