Expand my Community achievements bar.

Disable characters typing into date/time field ?

Avatar

Level 2

Hi,

Is there a way to disallow characters typing into date/time field?

Thanks!

4 Replies

Avatar

Former Community Member

One way would be to declare the date-time value as "Calculated - Read Only" and select a runtime property as current date. Depending on your objectives you could declare the value as "Protected" or "Read Only" also.

Untitled.png

Steve

Avatar

Level 2

Hi Steve,

I didn't explained myself well.

The goal is not to make field read only but to disallow users to type any

characters beside numeric.

Is that possible ?

-Yan.

Avatar

Former Community Member

Yan,

Date fields are inherently alphanumeric. You could use a simple numeric field with a display and validation pattern of num{99999999}. I am a programmer by trade so I like to write code. I find text fields easier to manipulate. For example, for a text field with a max length of 8...

// form1.page1.subform1.date_::exit - (JavaScript, client)

if (!(this.isNull || this.rawValue == "")) {

          var str = this.rawValue;

          var regExp = /\D/;

          if (regExp.test(str)) {

   xfa.host.messageBox("Date must contain digits only.");

          }

          else {

    if (str.length != 8) {

      xfa.host.messageBox("Date must contain 8 digits (MMDDYYYY).");

    }

          }

}

This forces 8 digits. If you want to validate MM, DD and YYYY plan accordingly.

Steve

Avatar

Level 10

Hey Steve, quick question, I thought if you used the .isNull test you didn't need to also do the =="" ? Or does checking for "" do something different?

According to John Brinkman the two ways to test for null are: "field.rawValue === null" or "field.isNull".

I keep seeing different variations and want to make sure I'm doing it the correct way.