Show all the mandatory fields at the end of the form

Certified Associate Developer

Hi,

I have a requirement which says, when a mandatory field is missed, there should be an error displayed at the bottom of the page with the missed field name so the user can see what has been missed without having to scroll up the page. Could anybody please suggest what's the best approach?

Thanks

  Discussion posts and replies are publicly visible

  • Hi Shruti,

    as far as i know there is not any automated way to do this so what i would do is to use validation messages:

    load(
      local!text,
      local!text2,
      a!formLayout(
        contents: {
          a!textField(
            label: "Text 1",
            required: true,
            value: local!text,
            saveInto: local!text
          ),
          a!textField(
            label: "Text 2",
            required: true,
            value: local!text2,
            saveInto: local!text2
          )
        },
        buttons: {
          a!buttonLayout(
            primaryButtons: {
              a!buttonWidgetSubmit(
                label: "SUBMIT"
              )
            }
          )
        },
        validations: {
          a!validationMessage(
            message: "Text 1 is missing",
            validateAfter: "SUBMIT",
            showWhen: or(isnull(local!text),local!text="")
          ),
          a!validationMessage(
            message: "Text 2 is missing",
            validateAfter: "SUBMIT",
            showWhen: or(isnull(local!text2),local!text2="")
          )
        }
      )
    )

    But maybe there is other, more sophisticated way, I don't know.

    Best,

    Erik

  • +1
    Certified Lead Developer
    You can use the validations attribute of a!formLayout() as this will appear at the bottom. If not using a!formLayout() just drop a section at the bottom of your components that just has the validations value in there.
    You will have to test each field manually using isnull() or similar but if you wrap your error messages in a!validationMessage() you can choose to only have them fire on SUBMIT.
  • Hi,

    I guess we don't best approach for displaying the fields that are not filled by the users but we can display and hide any field using the showWhen parameter. You need to create a dynamic or duplicate section which display fields on the condition basis if user not filled the mandatory field and try submits the form at the bottom of the page.

    Steps:

    1. Need to find the mandatory fields.
    2. Create a new section(boxLayout) with these fields and with style "warn".
    3. Add a new save to the button and save a true/false value in local variable.
    4. Make the button submit-able if all the required fields are filled.
    5. Display the section/fields on the basis of local variable and null condition.

    If you find any better solution for this please let me know as well.

    Thanks
    Aditya