Skip to main content
carlosd4386
March 19, 2024
Question

Problem with dateField and Button

  • March 19, 2024
  • 2 replies
  • 0 views

Hi,

I would like the button to be active by default if no date is selected or if a date equal to or after today is selected. And at the same time, the button is disabled if an invalid date or date older than today is entered.

The problem is that I can't differentiate when the user enters a wrong date and when they leave the field empty.

a!localVariables(
  local!dueDateAux,
  {
    a!dateField(
      label: "Due Date",
      value: ri!dueDate,
      saveInto: {
        ri!dueDate,
        a!save(local!dueDateAux, today())
      },
      validations: if(
        ri!dueDate >= today(),
        {},
        "Incorrect date format or date before current date"
      )
    ),
    a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          disabled: ri!dueDate < today(),
          submit: true
        )
      }
    )
  }
)

2 replies

konduruc733182
March 19, 2024

 Hello [mention:85a6635015f1485990f123340a4109bb:e9ed411860ed4f2ba0265705b8793d05] 

a simple null check before evaluating your disable condition would suffice your requirement.

But I would say keeping it disabled when it is blank also is a good option, unless you want to accept a null value.

a!buttonWidget(
          label: "Submit",
          disabled: if(
            a!isNullOrEmpty(ri!dueDate),
            {},
            ri!dueDate < today()
          ),
          submit: true
        )

mikes0011
Brainy
March 19, 2024

a!buttonWidget(
  label: "Submit",
  disabled: and(
    a!isNotNullOrEmpty(ri!dueDate),
    ri!dueDate < today()
  ),
  submit: true()
)