Can I use the rules macro to make fields mandatory based on condition in another field?

Matt Martin March 5, 2019

I am using the rules macro to dynamically display and hide fields and I'd like to extend that functionality so that, as well as unhiding fields, they are also made mandatory when they are visible. I'd also like the inverse of this meaning, when they are hidden, they are no longer mandatory.

I tried hunting through the rules functions and I cannot see one that sets field properties. Only field values. 

Thanks

1 answer

1 accepted

2 votes
Answer accepted
fbunting March 29, 2019

Yes, you can do this, by having two rules macros ... one for showing/hiding the second field, and the other to make it "required", by adding a Validation rule.

Details:

By "rules macro" I assume you mean the Confiform Rules for Field Definition macro.   (I believe that in previous Confiforms versions the macro had a slightly different name, Confiforms Field Definition Rules, but I think they have the same or similar parameters.)

So you would need two rules macros -- one for showing/hiding the second field, and the other for making it required. I won't go into the first macro, since you seem to have that working ... but configuring the second one is quite different.

So lets say Field1 is a drop-down, with option IDs a1, a2, etc., and you want it to make Field2 required if Field1=a1.

Configure the second macro as follows:

  • Field name (or regular expression) - Field2 (the field you want to make required)
  • Condition - Field1:a1 (the field whose value you want to check)
  • Action to execute - Set to to Validation rule
  • Message to show when validation rule matches - "Field2 is now mandatory."
  • Validation rule - Set to .+ (this matches any non-empty value ... basically making it required).
Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 29, 2019
Like # people like this
fbunting March 30, 2019

Alex, interesting ... I forgot about that Tutorial.

But I notice that it is a slightly different solution. Your tutorial sets up the rules macro parameters as follows:

  • Field name (or regular expression) - Leave blank (this triggers the rule on form submit)
  • Condition - Field1:a1 AND Field2:[empty]
  • Action to execute - Set to to Validation rule
  • Message to show when validation rule matches - "Field2 is now mandatory."
  • Validation rule - Leave blank.

Both solutions seem to work just fine.  Is there some advantage you can see between them?

Like Loren likes this
Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2019

Both will work (and I like yours better), but the one in our tutorial does not require any knowledge of regular expressions (which feels complicated to many users)

Like # people like this
Richard Ye April 17, 2020

I'm trying to add multiple fields to be set to be required, but the rule only checks the first. I have the in a comma separated list, but I have tried regex matching to those fields which also failed. 

What would I do as well if the field that I want to set to be required is a multiselect or user or dropdown?

img1.pngimg2.png

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 17, 2020

What type of rule this is?

To validate multiple fields to be required you set the condition that matches the error case and set the message to show (that is using the validation rule)

There is no need to set field names, as this is not what tells required fields

See this page on how to use validation rules - https://wiki.vertuna.com/display/CONFIFORMS/Conditional+validation+for+required+field

Richard Ye April 20, 2020

It is a validation rule.

In that case, where can I find a list of error cases for each type of field (dropdown, radio group, user etc)?

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2020

Not sure I get the question.. you decide the condition for the rule to "fail" and you decide what error message to show.

With validation rule you describe the condition that is illegal for submission and what message to show to the user when this happens

Richard Ye April 20, 2020

I have a text field where I want a user to input a title, and I want a conditional rule that checks to see if the user has typed something in it. For text fields, myField:[empty] is the condition that is illegal for submission. 

My question is, what is the equivalent illegal condition for other field types such as dropdowns, radio groups, or user fields? Or is "[empty]" the condition that can satisfy my needs for any field type?

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2020

Same [empty] check can be applied to any field type

https://wiki.vertuna.com/display/CONFIFORMS/ConfiForms+Filters

Like Richard Ye likes this
David Scatchell May 20, 2020

I am trying to get this working for a drop down scenario but its not working. 

 

I have a drop down with ID's as text like, "Sch", "Usch", "Ex". 

Use case is: 

IF a user selects "Usch"

Then another text field is required.  Field name is called "CDBFUnplanned"

Field CDBFUnplanned is checked as Required.

Rule is setup as follows

Condition = ReleaseType:Usch AND CDBFUnplanned:[empty] 

Action = Validation Rule

Field name (or regular expression) = Empty

When I go back to the form if the hidden field CDBFUnplanned is still required if another Release Type is selected. 

 

Any ideas?

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2020

You cannot have a field set as required in Field Definition and accept empty values into it. 

Field should be set as not required.

See an example https://wiki.vertuna.com/display/CONFIFORMS/Conditional+validation+for+required+field

David Scatchell July 22, 2020

Coming back to this. 

 

Field is set as Not Required but the examples are just not working.  Kind of a different use case now. 

 

When Release Type is set to Sch (The id) I would like to make a text field required. 

This is how I have it setup. 

 

Condition

ReleaseType:Sch AND BusinessValue:[empty]

Action to Execute: Validation Rule

Field Name : Blank

Message: Business Value is required if Scheduled

 

Business Value is not required in the field definition

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2020

Very quick test form

http://recordit.co/BcJLW1VUXU

And the storage format for this test form:

<ac:structured-macro ac:macro-id="256194ed-e1ba-42b1-94cf-c7b17966768f" ac:name="confiform" ac:schema-version="1">
<ac:parameter ac:name="formName">myform</ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:macro-id="ee91f97f-045f-4ea5-9300-0c423801d289" ac:name="confiform-entry-register" ac:schema-version="1">
<ac:parameter ac:name="formName">myform</ac:parameter>
<ac:parameter ac:name="type">Embedded</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
<p>
<ac:structured-macro ac:macro-id="c558e2db-b100-4e9e-a15a-141e4f2437f4" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">ReleaseType</ac:parameter>
<ac:parameter ac:name="fieldLabel">ReleaseType</ac:parameter>
<ac:parameter ac:name="values">false[Sch=Sch|NA=NA|]</ac:parameter>
<ac:parameter ac:name="type">select</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="84656bb9-34a4-4f1d-adfc-3687632634e7" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">BusinessValue</ac:parameter>
<ac:parameter ac:name="fieldLabel">BusinessValue</ac:parameter>
<ac:parameter ac:name="type">text</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="949d5236-5d81-4680-82ab-5c6a4e0ff3b6" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="condition">ReleaseType:Sch AND BusinessValue:[empty]</ac:parameter>
<ac:parameter ac:name="fieldName">Business Value is required if Scheduled</ac:parameter>
<ac:parameter ac:name="action">Validation rule</ac:parameter>
</ac:structured-macro>
</p>
</ac:rich-text-body>
</ac:structured-macro>
David Scatchell July 23, 2020

This works thank you! 

 

The reason I thought it wasn't working was that I have several required fields and was not filling out the whole form when testing the use case. 

 

The message only pops up after every other required field criteria is met. 

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2020

Yes, that is an additional rule and that is applied after all the standard rules are met

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events