How to validate fields on hidden section?

Certified Senior Developer

Hi,

I have a form with 2 button tabs A and B. Each one displays a section with fields (section A and Section B).

Initially, the section A is visible (section B not visible).

How may I validate the fields of the section B?

My Submit button validates only the visible fields section, so, if fields of section A are correct (and fields of Section B are not), the form is wrongly submitted.

Regards

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Ok I understand, thank you Mike.

  • 0
    Certified Senior Developer
    in reply to cedric01

    A last thing, how would you do what I need with a headerContentLayout?
    (we have no formLayout just a headerContentLayout)

    docs.appian.com/.../Header_Layout.html

  • 0
    Certified Lead Developer
    in reply to cedric01

    You'd need to put the validation in one of your SectionLayouts then.

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Yes but in that case, if the sectionA is visible, and sectionB hidden (with some fields in error).

    I will still have my problem, the submit button will not trigger the validation of the sectionB errors...
    Or maybe I'm missing something.

  • 0
    Certified Lead Developer
    in reply to cedric01

    My first suggestion would be to have a common, informational, top-level section that shows up regardless of which "tab" your user is on.

    If not, the solution is still easy: you just duplicate the same validation code across all your sections.  Any given section will have a section-level validation showing i.e. "validation error(s) found in Section A", which would be an array showing a similar message for any section(s) currently reading a validatione error (useful if you have very many).  The advantage here is that it's not too hard to scale up to handle many sections - the only real up-front lift is coding the local variable determining the individual section's error state, and even then all you're really doing is duplicating the "validations" code from the individual components within that section.

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    but how can you have a top level layoutSection ?
    (as a sectionLayout can not contain others layoutSection children)

  • 0
    Certified Lead Developer
    in reply to cedric01

    It would just be an extra section layout that always appears at the top of the current form (think of having an information overview header) which stays constant despite which tab the user clicks into.  There wouldn't need to be a parent/child relationship (since you're correct in that you can't nest sections at any level).

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Oh ok, I see...

    The only piece I miss, is how to save the result of validations from fields-section to this top level section with this common local var.

    Would you have a little example please ?

    a!localVariables(
    	local!sectionAHasValidationError: null,
    	
    	// top level section
    	a!sectionLayout(
    		validations: local!sectionAHasValidationError
    	),
    	
    	// section with error
    	a!sectionLayout(
    		fieldA,
    		fieldB,
    		validations: {
    		  if(
    			and(isnull(fieldA), isnull(fieldB)),
    			a!validationMessage(
    			  message: "You must enter either a phone number or an email address!",
    			  validateAfter: "SUBMIT"
    			), /* How to save the validations to  local!sectionAHasValidationError ? */
    			{}
    		  )
    		}
    	)
    )

  • Try this out:

    a!localVariables(
      local!fieldA1,
      local!fieldA2,
      local!fieldB1,
      local!fieldB2,
      local!display: "Section A",
      
      local!sectionAHasValidationError: or(
        rule!APN_isEmpty(local!fieldA1),
        rule!APN_isEmpty(local!fieldA2)
      ),
      local!sectionBHasValidationError: or(
        rule!APN_isEmpty(local!fieldB1),
        rule!APN_isEmpty(local!fieldB2)
      ),
      
      local!validations: reject(
        rule!APN_isEmpty,
        {
          if(local!sectionAHasValidationError,"Error in Section A",null),
          if(local!sectionBHasValidationError,"Error in Section B",null)
        }
      ),
    
      {
        /*top level section*/
        a!sectionLayout(
          label: "Validation Info",
          validations: local!validations
        ),
        
        a!buttonArrayLayout(
          align: "START",
          buttons: {
            a!buttonWidget(
              label: "Section A",
              value: "Section A",
              disabled: local!display="Section A",
              saveInto: local!display
            ),
            a!buttonWidget(
              label: "Section B",
              value: "Section B",
              disabled: local!display="Section B",
              saveInto: local!display
            )
          }
        ),
    
        a!sectionLayout(
          label: "Section A",
          showWhen: local!display="Section A",
          contents: {
            a!textField(
              label: "Field A1",
              value: local!fieldA1,
              saveInto: local!fieldA1,
              required: true
            ),
            a!textField(
              label: "Field A2",
              value: local!fieldA2,
              saveInto: local!fieldA2,
              required: true
            )
          }
        ),
        a!sectionLayout(
          label: "Section B",
          showWhen: local!display="Section B",
          contents: {
            a!textField(
              label: "Field B1",
              value: local!fieldB1,
              saveInto: local!fieldB1,
              required: true
            ),
            a!textField(
              label: "Field B2",
              value: local!fieldB2,
              saveInto: local!fieldB2,
              required: true
            )
          }
        )
      }
    )

  • 0
    Certified Senior Developer
    in reply to Chris

    Thank you Chris, it works great but you don't use the validation of SectionA and SectionB...

    I would have love to keep the validation of these 2 sections, as these later are in 2 sub-interfaces.


    Is there not any way to reuse the validations and then transmit it (as an object reference) to the main form interface?