Skip to main content
varunb579494
November 24, 2022
Question

Validations not working as expected

  • November 24, 2022
  • 1 reply
  • 0 views

I have few issues associated with validations.

I have included the code within asking all my questions in comments and instructions. Please guide.

Thanks

a!localVariables(
  local!testValueToo,
  {
    a!textField(
      label: "Test Me too",
      instructions: "Enter a value less than 12. The validation should pop up without pressing Submit which shouldn't be the case if validation group is given. Please suggest correct validation group configuration.",
      value: local!testValueToo,
      saveInto: local!testValueToo,
      validationGroup: "SUBMIT", 
      validations: if(
        len(local!testValueToo) < 12, /*When form loads, the value of local!testValueToo
        is null making its length as zero and 0<12 which is true, so validation should fail
        and message should appear (as validation group is not working, so it should appear
        whenever condition is true), BUT it's not appearing. What are the requirements to
        make validation work properly*/
        "Contains less than 12 characters.",
        null
      )
    ),
    /* Press this multiple times in a row without pause. This will run saveInto skipping 
    all validations, make sure atleast one validation fails. Then keep on pressing. That's a
    wierd issue. */
    a!buttonLayout(
      primaryButtons: a!buttonWidget(
        tooltip: "Press me multiple times in a row without pause. I will then run saveInto skipping all the validations.",
        label: "submit",
        submit: false,
        validate: true,
        validationGroup: "SUBMIT",
        saveInto: {
          a!save(local!testValueToo, "testToo")
        }
      )
    )
  }
)

1 reply

stefanhelzle0001
Brainy
November 24, 2022

Validations are only evaluated when the value is NOT null.

You might want to consider switching "required" to true.

Validations work on real values, while "required" makes the field mandatory.