Hi,
I have a Jira form using checkboxes, so for each question I basically have:
Form checklist question:
[ ] N/A
[ ] Option 1
[ ] Option 2
[ ] Option 3
So upon submission, I need to validate the following:
1) Form can't be submitted empty (w/o selecting any options)
2) Form can't be submitted without selecting either "N/A" or at least one other option from options 1/2/3.
So we must consider:
- 2.1) IF "N/A" is selected, no other option can be selected and submitted
- 2.2) IF "N/A" is not selected then I have to have at least one other option selected
I was able to accomplish #1 above with the following:
(! issue.customfield_1 || issue.customfield_1.length > 0) && (! issue.customfield_2 || issue.customfield_2.length > 0) && so on...
Now, to accomplish #2, I've tried the following (1 field example):
(!!issue.customfield_1 && issue.customfield_1.some(it => it.value == "N/A")) && (!!issue.customfield_1 && issue.customfield_1.length = 1)
which is attempting to validate "IF N/A checkbox is selected AND the count on the number of checkboxes select = 1 THEN pass the validation" BUT this doesn't seem to be working...
What am I missing? Or what's the best path to validate this?
Thank you!
Hi,
for #1, I believe you want this instead:
!! issue.customfield_1 && issue.customfield_1.length > 0 && !! issue.customfield_2 && issue.customfield_2.length > 0
which forces each field to be non-empty.
As for #2, focusing on a single field first, and already knowing from #1 that no field is empty:
issue.customfield_1.some(it => it.value == "N/A") && issue.customfield_1.length == 1
|| !issue.customfield_1.some(it => it.value == "N/A")
Combining the two:
!! issue.customfield_1 && issue.customfield_1.length > 0 && !! issue.customfield_2 && issue.customfield_2.length > 0
&& issue.customfield_1.some(it => it.value == "N/A") && issue.customfield_1.length == 1
|| !issue.customfield_1.some(it => it.value == "N/A")
&& issue.customfield_2.some(it => it.value == "N/A") && issue.customfield_2.length == 1
|| !issue.customfield_2.some(it => it.value == "N/A")
If you end up with an expression that's too long (Jira expressions are limited to 1000 characters if I remember correctly) , you can always create a validator per field instead (which will also make error messages clearer).
David
Thanks, David!
That worked. I just had an issue with the size but broke it down to several validators which solved the problem.
Cheers!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.