Validate dates and times

Hello! I need help :)

I have a doubt that I do not know how to do it.

I want to validate the hours field and the minutes field in this way:

• From April 1 to September 30, effective hours will be 7.

• From October 1 to March 31, the effective hours will be 7 and the minutes will be 33.

in my code:

a!sideBySideItem(
item:

a!integerField(
labelPosition: "ABOVE",
value: ri!Regis.hours,
saveInto: {ri!Regis.hours},
align: "LEFT"
),
width: "MINIMIZE"
),
a!sideBySideItem(
item:
a!textField(
labelPosition: "ABOVE",
value: " Hours ",
readOnly: true
),
width: "MINIMIZE"
),
a!sideBySideItem(
item:

a!integerField(
labelPosition: "ABOVE",
value: ri!Regis.minute,
saveInto: {ri!Regis.minute}
),
width: "MINIMIZE"
),
a!sideBySideItem(
item:
a!textField(
labelPosition: "ABOVE",
value: " Minute",
readOnly: true
)
)

thanks so much!!

  Discussion posts and replies are publicly visible

Parents Reply
  • In that case (where you want the fields to be auto populated), you can do that using if condition for your minute field as your hour filed is always going to be 7 hours. Use the following in display value for the Integer Field and should be fine. You can refine the following to make it more compact by having the value to check against in some local variables or constants to use in IF condition:

    For example, in display value field for your minutes field you can use:

    if(
    OR(
    todate(now()) >= todate("4/1/",year(now())),
    todate(now()) <= todate("9/30/",year(now()))
    ),
    0,
    30
    ),

Children
  • depending on the current date of when the page will be,  I just have to enter each field  7 hours From April 1 to September 30 7 hours and 33 minutes From October 1 to March 31

  • load(
      local!date: today(),
      local!hours,
      local!minute,
      local!validationData: if(
        and(
          local!date >= todate(
            concat(
              "04/01/",
              year(
                local!date
              )
            )
          ),
          local!date <= todate(
            concat(
              "09/30/",
              year(
                local!date
              )
            )
          )
        ),
        {
          hours: 7,
          minutes: 0
        },
        {
          hours: 7,
          minutes: 33
        }
      ),
      {
        a!sideBySideLayout(
          items: {
            a!sideBySideItem(
              item: a!integerField(
                labelPosition: "ABOVE",
                value: local!hours,
                saveInto: {
                  local!hours
                },
                align: "LEFT",
                validations: if(
                  isnull(
                    local!hours
                  ),
                  {},
                  if(
                    local!hours > tointeger(
                      local!validationData.hours
                    ),
                    "Not Valid",
                    {}
                  )
                )
              ),
              width: "MINIMIZE"
            ),
            a!sideBySideItem(
              item: a!textField(
                labelPosition: "ABOVE",
                value: " Hours ",
                readOnly: true
              ),
              width: "MINIMIZE"
            ),
            a!sideBySideItem(
              item: a!integerField(
                labelPosition: "ABOVE",
                value: local!minute,
                saveInto: {
                  local!minute
                },
                validations: if(
                  isnull(
                    local!minute
                  ),
                  {},
                  if(
                    local!minute > tointeger(
                      local!validationData.minutes
                    ),
                    "Not Valid",
                    {}
                  )
                )
              ),
              width: "MINIMIZE"
            ),
            a!sideBySideItem(
              item: a!textField(
                labelPosition: "ABOVE",
                value: " Minute",
                readOnly: true
              )
            )
          }
        )
      }
    )

    so when your form is loading ,we are saving date in a local variable based on local date local variable ,we are getting validation data,

    like if date is in between 04/01/year and 09/30/year the the   validation data will be 

    {
    hours: 7,
    minutes: 0
    }

    other than that the validation data will be

    {
    hours: 7,
    minutes: 33
    }

    so if user enter more values than that then showing a validation message  like "Not Valid "