Skip to main content
October 29, 2021
Question

Hi guys,

  • October 29, 2021
  • 3 replies
  • 0 views

I am  trying to do some validations using two fields scheduled date and assignee.

Sheduled date should be mandatory field if the user add any name in assignee field.

If there is no name in assignee field the system should allow to continue without scheduled date.

3 replies

stewart.burchell
October 29, 2021

Every User Interface input component has a "required" attribute. You can set this using a rule, and you can make the rule examine the value of the assignee field. Your rule can simply check if the assignee's value is null:

richardm900458
October 31, 2021

additional info: that this "required" parameter of an UI component is working properly you need to have a buttonwidget with the parameter "submit : true" or at least if the button  parameter "submit" is false or not filled (default value is false) the paramater "validate" needs to be "true". 

csteward
November 1, 2021

Adding some sample code illustrating Stewart and Richard's notes, which I agree with:

a!localVariables(
  local!date,
  local!assignee,

  a!formLayout(
    label: "Conditional Required Fields",
    contents: {
      a!columnsLayout(
        columns: {
          a!columnLayout(),
          a!columnLayout(
            contents: {
              a!sideBySideLayout(
                items: {
                  a!sideBySideItem(
                    item: a!dateField(
                      label: "Date",
                      value: local!date,
                      saveInto: local!date,
                      required: not(rule!APN_isEmpty(local!assignee))
                    )
                  ),
                  a!sideBySideItem(
                    item: a!pickerFieldUsers(
                      label: "Assignee",
                      value: local!assignee,
                      saveInto: local!assignee
                    )
                  )
                }
              )
            }
          ),
          a!columnLayout()
        }
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          validate: true,
          submit: true
        )
      }
    )
  )
)