Skip to main content
January 25, 2024
Question

validation is not working in form layout

  • January 25, 2024
  • 11 replies
  • 0 views

 a!textField(
                                label: "Title:",
                                labelPosition: "JUSTIFIED",
                                value: local!data.requestTitle,
                                saveInto: {a!save(local!data.requestTitle, save!value) },
                                validations:(
                                if(a!isNullOrEmpty(local!data.requestTitle),
                                "Title is Required ",
                                {},
                                )),
                                
                             refreshAfter: "KEYPRESS",
                            characterLimit: 100,
                            required: true,
                        ),
                 buttons: a!buttonLayout(
                  primaryButtons: {
                    a!buttonWidget_23r3(
                      label: "Submit",
                      style: "PRIMARY",
                      submit: true,
                      saveInto: { },
                      loadingIndicator: true(),
                      validate: true(),
                    )
                  },
                  secondaryButtons: {
                    a!buttonWidget_23r3(
                      label: "Cancel",
                      style: "NORMAL",
                      submit: true,
                      validate: false,
                      value: true,
                      saveInto: ri!cancel
                    )
                  }
                )

i added validation if title field is empty then validation should display saying "title is required" but the validation is not working in above code .can someone please help

    11 replies

    harshitb6843
    January 25, 2024

    One of the blocks in your if() in validation has to be empty. Otherwise, no matter if the value is there or not, it will always throw a validation. 

    Secondly, did you set validate: true in the button?

    sabat0002Author
    January 25, 2024

    i have corrected both the points but still validation is not happening

    harshitb6843
    January 25, 2024

    The code seems a bit off. I think you pasted the button's code in between the textField. I have simplified the code for you. 

    a!textField(
      label: "Title:",
      labelPosition: "JUSTIFIED",
      value: local!data.requestTitle,
      saveInto: local!data.requestTitle,
      refreshAfter: "KEYPRESS",
      characterLimit: 100,
      required: true,
    ),

    Now can you tell me what is happening when you click on the button?

    konduruc733182
    January 25, 2024

    Hello [mention:85ca6a2722324ac4b08c9eda0b5e1851:e9ed411860ed4f2ba0265705b8793d05] 

    Why use validation if its just a null check. you can use required and a required message. unless you want to evaluate before submit.

    sabat0002Author
    January 25, 2024

    I want to validate the textbox without clicking on submit button.

    The requirement is without clicking on submit button ,the validation message should be displayed under each field

    konduruc733182
    January 25, 2024

    I don't think that's an option. You will have to go with required parameter. Validations only work when you have a non null value to deal with.


    stefanhelzle0001
    Brainy
    January 25, 2024

    Validations are only triggered if there is a non-null value. If you want to make a field required, set "required" to true.

    mohammadjavidbashaa9600
    March 6, 2024

    In this case you would not need to set "submit" to true (in fact you should probably set it to FALSE); keep the "validate" parameter set to true;