Simple tutorial on how to use ConfiForms Field Definition Rules#Showfield and it's counterpart ConfiForms Field Definition Rules#Hidefield ConfiForms Rules for Field Definitions to show and hide fields conditionally

Consider a form that has few fields like this


 

 


// this rule will hide the "details" field when a checkbox field "showDetails" is unchecked and will show the "details" field otherwise

// this rule shows an extra field when you select an "other" option in the "options" dropdown field (and hides it otherwise)


And the standard layout for the form


Custom layout for the same form

Some custom layout for the same form

<ac:structured-macro ac:macro-id="a356f4a8-bdfc-4f79-bc45-56c1abc82106" ac:name="confiform" ac:schema-version="1">
        <ac:parameter ac:name="formName">myform</ac:parameter>
        <ac:rich-text-body>
          <p>
            <ac:structured-macro ac:macro-id="94923a9b-bc51-4272-a4f3-e1711836ea84" ac:name="confiform-field-definition" ac:schema-version="1">
              <ac:parameter ac:name="fieldName">Field1</ac:parameter>
              <ac:parameter ac:name="fieldLabel">Field1</ac:parameter>
              <ac:parameter ac:name="type">text</ac:parameter>
            </ac:structured-macro>
          </p>
          <p>
            <ac:structured-macro ac:macro-id="faa26a33-b268-415f-bda2-ca26354f8237" ac:name="confiform-field-definition" ac:schema-version="1">
              <ac:parameter ac:name="fieldName">showDetails</ac:parameter>
              <ac:parameter ac:name="fieldLabel">Let me provide some details</ac:parameter>
              <ac:parameter ac:name="type">checkbox</ac:parameter>
            </ac:structured-macro> </p>
          <p>
            <ac:structured-macro ac:macro-id="cfde56ca-1d74-40f5-a437-105c7760d598" ac:name="confiform-field-definition" ac:schema-version="1">
              <ac:parameter ac:name="fieldName">details</ac:parameter>
              <ac:parameter ac:name="fieldLabel">Details</ac:parameter>
              <ac:parameter ac:name="type">textarea</ac:parameter>
            </ac:structured-macro>
          </p>
          <p>
            <ac:structured-macro ac:macro-id="602a7b0b-1968-4c3a-b9f3-89a41692c486" ac:name="confiform-field-definition" ac:schema-version="1">
              <ac:parameter ac:name="fieldName">options</ac:parameter>
              <ac:parameter ac:name="fieldLabel">Choose an option</ac:parameter>
              <ac:parameter ac:name="values">false[1=Option 1|2=Option 2|3=Option 3|4=Let me provide my option|]</ac:parameter>
              <ac:parameter ac:name="type">select</ac:parameter>
            </ac:structured-macro> </p>
          <p>
            <ac:structured-macro ac:macro-id="0ff45634-8fd7-4f78-a2ef-05e15bb033d8" ac:name="confiform-field-definition" ac:schema-version="1">
              <ac:parameter ac:name="fieldName">userOption</ac:parameter>
              <ac:parameter ac:name="fieldLabel">My option</ac:parameter>
              <ac:parameter ac:name="type">text</ac:parameter>
            </ac:structured-macro>
          </p>
          <p>
            <br/>
          </p>
          <p>// this rule will hide the "<em>details</em>" field when a checkbox field "<em>showDetails</em>" is unchecked and will show the "<em>details</em>" field otherwise</p>
          <p>
            <ac:structured-macro ac:macro-id="7299078c-2038-4881-976f-48dce42b8cc5" ac:name="confiform-field-definition-rules" ac:schema-version="1">
              <ac:parameter ac:name="condition">showDetails:false</ac:parameter>
              <ac:parameter ac:name="fieldName">details</ac:parameter>
              <ac:parameter ac:name="action">Hide field</ac:parameter>
              <ac:parameter ac:name="actionFieldName">showDetails</ac:parameter>
              <ac:parameter ac:name="withReverseRule">true</ac:parameter>
            </ac:structured-macro>
          </p>
          <p>// this rule shows an extra field when you select an "other" option in the "<em>options</em>" dropdown field (and hides it otherwise)</p>
          <p>
            <ac:structured-macro ac:macro-id="7b9d37e2-7f3a-4dff-a7b3-d88d3402b3b4" ac:name="confiform-field-definition-rules" ac:schema-version="1">
              <ac:parameter ac:name="condition">options:4</ac:parameter>
              <ac:parameter ac:name="fieldName">userOption</ac:parameter>
              <ac:parameter ac:name="action">Show field</ac:parameter>
              <ac:parameter ac:name="actionFieldName">options</ac:parameter>
              <ac:parameter ac:name="withReverseRule">true</ac:parameter>
            </ac:structured-macro>
          </p>
          <p>
            <br/>
          </p>
        </ac:rich-text-body>
      </ac:structured-macro>