Validation on empty field condition not working in fragment validator

Hi,

Please can someone advise why the validation on the || ! area_value condition does not work in the code below ?

if (area_value <= 0 || !area_value) {

return {
valid: false,
error: ‘Area value must not be empty or 0’
}
}
return true;

If I enter 0 or less than, I get the error. If I save the field without any value in it, I get no error! I’ve also tried:
area_value === ‘’
area_value === null

Neither work.

Version of Create is 2023.1

Thanks,

Mark

always do not area_value first as that will work if it’s null or empty but if the area_value <= 0 comes first you will get an error as it doesn’t exist

Hi Mark,

Did Robinli’s advice help? do you need any more support with this?

The validator will not fire if the field is empty, they are only used to validate an actual value.
You should mark the field as Required if you don’t want an emty field to be accepted, and then your own validator can just deal with the <=0 check.

Note that you can also set min/max values for integer Data Types, possibly preventing the need for your own validator anyway.

2 Likes

Thanks - in the end the validator did not fit the requirement since the field had to be read-only too, so we found another solution by pending the case in relation to certain conditions.