Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add validation only if the value is checked?

jun lee
Contributor
March 28, 2022

There are two custom fields(ReqApprove, DeployApprove) in radio button format, and the default value is empty. Even if there is no value, the issue can be closed. However, if there is a value, it should be checked for yes.
Is there a way to add the above conditions to one validation? If I add two individually(validation for ReqApprove, and validation form DeployApprove), Jira always check Yes of two custom fields.

Can you tell me how to add just one validation?

 

 

1 answer

0 votes
Benjamin
Community Champion
March 28, 2022

Hi @jun lee ,

 

Since you can add both, why can't you just add one? or is the question about just meeting one of the validators. 

 

If you are looking into more of conditional validators, you may want to consider add-ons. Fro example, JSU or JMWE.

 

-Ben

jun lee
Contributor
March 29, 2022

Hi

 

I added validation like below.

  • cfValues['ENM_ReqApprove']?.value == 'Yes'
  • cfValues['ENM_DeployApprove']?.value == 'Yes'

 

When I added validation like this, value of two custom fields should be checked as I asked. 

So I want to make one validation only if the value is checked.

If you know, tell me the script. I don't know the script.

Benjamin
Community Champion
March 29, 2022

You would do something like two pipes in-between the two statements in one line as seen below.

 

cfValues['ENM_ReqApprove']?.value == 'Yes' || cfValues['ENM_DeployApprove']?.value == 'Yes'

jun lee
Contributor
March 29, 2022

I added your script, but Jira requires value even though two custom fields are empty. I want to validation script only if custom field is not empty.

case1) field A is empty & field B is empty -> can be closed

case2) field A is not empty & field B is empty -> cannot be closed. require field A value "Yes"

case3) field A is empty & field B is not empty -> cannot be closed. require field B value "Yes"

case4) field A is not empty & field B is not empty -> cannot be closed. require field A and B values "Yes"

Suggest an answer

Log in or Sign up to answer