Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Custom validation that won't give invalid value error

Participant ,
Sep 03, 2021 Sep 03, 2021

Hi all,

I need some help. I have a form that has a field (Total Funding Request) that can be filled in by someone entering a value or a sum of 3 other fields (Year 1 Multi Funding, Year 2 Multi Funding and Year 3 Multi Funding).

 

On those 3 fields I have under ‘Validate’ the 'Field value range' set, From:25000 To: 0 (as I want the numbers entered to be equal to or greater than 25,000 – not less –  and up to any number – that is why I set 0).

 

I have the ‘Total Funding Request’ field to ‘Calculate’ – ‘Value is the – ‘Sum (+)’ and I have picked the 3 fields (Year 1 Multi Funding, Year 2 Multi Funding and Year 3 Multi Funding). I also have under 'Validate' ‘Field value is in range’ set, From:25000 To: 0 (as I want the number entered to be equal to or greater than 25,000 – not less –  and up to any number – that is why I set 0).

 

The problem I am having is with (I think) the ‘Field value range’ on the ‘Total Funding Request’. If I put numbers in the three multi-year funding fields (and as long as they are over the 25,000 value) I get no warning. However, if I bypass the multi-year fields and go straight to the ‘Total Funding Request’ and put in a value, even if it’s over 25,000, I get a message that pops up that says: Invalid value: must be greater than or equal to 25,000. If I take the validation off I no longer get the error but I need it there if someone doesn’t choose the multi-funding option and goes straight to the ‘Total Funding Request’.

 

Is there some kind of script that can allow someone to put a value in to the ‘Total Funding Request’, restrict the value to be equal to or greater than 25,000 and won’t give me the warning that the value must be greater than 25,000?

 

Thanks

TOPICS
How to , JavaScript
3.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Sep 07, 2021 Sep 07, 2021

If you set 'Field value is in range:' as you originaly intended, you can use this as 'custom calculation script' of "Total Funding Request" field:

 

var a = Number(this.getField("Year 1 Multi Funding").value);
var b = Number(this.getField("Year 2 Multi Funding").value);
var c = Number(this.getField("Year 3 Multi Funding").value);
if(a==0 && b==0 && c==0)
event.rc = false;
else
event.value = a+b+c;

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 03, 2021 Sep 03, 2021

This is possible with a custom validation script. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 03, 2021 Sep 03, 2021

You can use this code as the field's custom validation script:

 

if (event.value && Number(event.value)<25000) {
	app.alert("The value must be 25,000 or more.");
	event.rc = false;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 03, 2021 Sep 03, 2021

This won't work, if OP put this code in fields as validation and still use sum+ it will still give alert when manually enter value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 07, 2021 Sep 07, 2021

Good morning Asim123,

 

As you stated I did put this in the 'Run custom validation script" and I still did get the warning alert. Is there a script I can put in the "Custom calculation script" that would eliminate the warning alert from comming up? Or is this an impossible request?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 07, 2021 Sep 07, 2021

Thanks Try67,

I did put this script in but as Asim123 mentioned I still got the warning alert. Is there a custom script I would need in the Calculate tab to make this work?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 07, 2021 Sep 07, 2021

The warning comes from the script. Just remove that line from it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 07, 2021 Sep 07, 2021

Sorry Try67,

 

I'm not sure what line you are refering to as I don't know scripting and I'm confused as I thought the script was to validate the field for a number equal to/over 25,000 and stop the alert from poping up if the number was over 25,000.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 07, 2021 Sep 07, 2021

This line:

app.alert("The value must be 25,000 or more.");
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 07, 2021 Sep 07, 2021

Thanks Try67,

I took that line out and I no longer get the warning but basically if someone puts a value that is under 25,000 it just doesn't allow that number to go in.

 

Is there no way to have the warning come up for values below 25,000 but no warning to come up for values equal to or greater than 25,000? Your orginal script had the warning come up in both senerios and now it doesn't come up at all leaving the person to wonder why it won't take their number (eventhough they should know that the application is for greater than 25,000).

 

Thanks again for helping me out.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 07, 2021 Sep 07, 2021

If you set 'Field value is in range:' as you originaly intended, you can use this as 'custom calculation script' of "Total Funding Request" field:

 

var a = Number(this.getField("Year 1 Multi Funding").value);
var b = Number(this.getField("Year 2 Multi Funding").value);
var c = Number(this.getField("Year 3 Multi Funding").value);
if(a==0 && b==0 && c==0)
event.rc = false;
else
event.value = a+b+c;

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2021 Sep 08, 2021

Setting the event.rc property in a calculation script is not the right way of doing it. Instead, just set the field's value to be empty, or zero.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 08, 2021 Sep 08, 2021
LATEST

Thank you very much Nesa the script worked like a charm.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines