Skip to main content
February 28, 2025
Solved

Validation not being enforced

  • February 28, 2025
  • 4 replies
  • 0 views

Hello,

I have submit disabled, validate set to true, required set to true but the required message only appears on one field when clicking save button.

Here is my code for the amount to refund field:

 

                a!sideBySideItem(
                  item: a!textField(
                    label: "Amount to Refund",
                    labelPosition: "ADJACENT",
                    value: if(
                      local!updatedStatus = "Closed - Full Refund",
                      a!currency(
                        "USD",
                        local!data.paymentAmount
                      ),
                      a!currency("USD", local!refundAmount)
                    ),
                    saveInto: local!refundAmount,
                    refreshAfter: "UNFOCUS",
                    required: if(
                      local!updatedStatus = "Closed - Partial Refund",
                      true,
                      false
                    ),
                    requiredMessage: "Amount to refund is required.",
                    disabled: if(
                      or(
                        local!updatedStatus <> "Closed - Partial Refund",
                        local!readonly = true
                      ),
                      true,
                      false
                    ),
                    validations: if(
                      or(
                        a!isNullOrEmpty(local!refundAmount),
                        and(
                          todecimal(local!refundAmount) > 0,
                          todecimal(local!refundAmount) <= todecimal(
                            local!data.paymentAmount
                          ) - 0.01
                        )
                      ),
                      null,
                      "Amount must be less than the original amount."
                    ),
                  )
                )

Here is my code for the tracking field:

                a!sideBySideItem(
                  item: a!textField(
                    label: "Return Tracking",
                    labelPosition: "ADJACENT",
                    value: local!requestDetails.returnTrackingCode,
                    saveInto: local!requestDetails.returnTrackingCode,
                    refreshAfter: "UNFOCUS",
                    characterLimit: 35,
                    required: if(
                      or(
                        local!updatedStatus = "Closed - Partial Refund",
                        local!updatedStatus = "Closed - Full Refund"
                      ),
                      true,
                      false
                    ),
                    disabled: if(
                      and(
                        local!readonly = false,
                        or(
                          local!updatedStatus = "Closed - Full Refund",
                          local!updatedStatus = "Closed - Partial Refund"
                        )
                      ),
                      false,
                      true
                    ),
                    validations: if(
                      len(
                        local!requestDetails.returnTrackingCode
                      ) >= 15,
                      null,
                      "Return Tracking must be at least 15 characters long."
                    ),
                    accessibilityText: "Return tracking input field"
                  )
                )

Here is my code for my save button: 

Please advise..

Thank you.

    Best answer by orlandos8991

    Hi, according to the documentation, when you don't pass any value to the a!currency() function, it returns the ISO code. So, when you click on the button, you will not get a "required value" message in the "Amount to be refunded" text field because the value will be "$". To fix this, I made some adjustments to your code. Refer the code below.

    a!sideBySideItem(
              item: a!textField(
                label: "Amount to Refund",
                labelPosition: "ADJACENT",
                value: if(
                  local!updatedStatus = "Closed - Full Refund",
                  a!currency("USD", local!data.paymentAmount),
                  if(
                    a!isNullOrEmpty(local!refundAmount),
                    local!refundAmount,
                    a!currency("USD", local!refundAmount)
                  )
                ),
                saveInto: local!refundAmount,
                refreshAfter: "UNFOCUS",
                required: if(
                  local!updatedStatus = "Closed - Partial Refund",
                  true,
                  false
                ),
                requiredMessage: "Amount to refund is required.",
                disabled: if(
                  or(
                    local!updatedStatus <> "Closed - Partial Refund",
                    local!readonly = true
                  ),
                  true,
                  false
                ),
                validations: if(
                  or(
                    a!isNullOrEmpty(local!refundAmount),
                    and(
                      todecimal(local!refundAmount) > 0,
                      todecimal(local!refundAmount) <= todecimal(local!data.paymentAmount) - 0.01
                    )
                  ),
                  null,
                  "Amount must be less than the original amount."
                )
              )
            )

    4 replies

    March 1, 2025

    Hi, according to the documentation, when you don't pass any value to the a!currency() function, it returns the ISO code. So, when you click on the button, you will not get a "required value" message in the "Amount to be refunded" text field because the value will be "$". To fix this, I made some adjustments to your code. Refer the code below.

    a!sideBySideItem(
              item: a!textField(
                label: "Amount to Refund",
                labelPosition: "ADJACENT",
                value: if(
                  local!updatedStatus = "Closed - Full Refund",
                  a!currency("USD", local!data.paymentAmount),
                  if(
                    a!isNullOrEmpty(local!refundAmount),
                    local!refundAmount,
                    a!currency("USD", local!refundAmount)
                  )
                ),
                saveInto: local!refundAmount,
                refreshAfter: "UNFOCUS",
                required: if(
                  local!updatedStatus = "Closed - Partial Refund",
                  true,
                  false
                ),
                requiredMessage: "Amount to refund is required.",
                disabled: if(
                  or(
                    local!updatedStatus <> "Closed - Partial Refund",
                    local!readonly = true
                  ),
                  true,
                  false
                ),
                validations: if(
                  or(
                    a!isNullOrEmpty(local!refundAmount),
                    and(
                      todecimal(local!refundAmount) > 0,
                      todecimal(local!refundAmount) <= todecimal(local!data.paymentAmount) - 0.01
                    )
                  ),
                  null,
                  "Amount must be less than the original amount."
                )
              )
            )

    March 3, 2025

    This was very helpful. Thank you!! :) 

    karumurua531442
    March 2, 2025

    hi [mention:cb000c01eb194af199ffedba27c1da75:e9ed411860ed4f2ba0265705b8793d05]  could try checking this and check if this can work for your scenario? a!validationMessage()

    stefanhelzle0001
    March 2, 2025

    This is how field validation works. The first click on a button with validate enabled, will set the whole interface into the validations state. Then all validations are evaluated. There is no validation before.