Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Restrict/Limit Length for field dynamically using JAVA Script

Avatar

Level 2

Hi,

     How do I dynamically restrict the lenght of the field? I could not use the maxChars property as it cannot be directly addressed. Based on certain conditions I would like to dynamically retrict the field length to 2 characters. Can anybody help?

I am able to capture the length using the below code: -

var

maxLen = this.value.oneOfChild.maxChars;

but how do I restrict the length of the field to 4 characters only ?

Regards,

Shishir.P

1 Reply

Avatar

Former Community Member

Something like this will work.

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

if (form1.page1.subform1.productID.isNull) {

  xfa.host.messageBox("The product ID is a mandatory field.");

}

else {

  var productID = this.rawValue;

  if (productID.length != 4) {

    xfa.host.messageBox("The product ID must be four characters in length.");

  }

}

This code assumes the product ID is a mandatory field.

Steve