Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript in PDF - Custom Keystroke Script

New Here ,
May 05, 2022 May 05, 2022

Hello,

 

I have a text field in my form that I'm trying to see if there is a way to « force » a certain format. So basically, I want them to put their postal code in that format : H1H 1H1 (letter - number - letter - space - number - letter - number). I also want the letters to be in capital letter. Is that possible and if so , how ?

 

Thank you !

TOPICS
Create PDFs , How to , JavaScript , PDF forms
2.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
May 05, 2022 May 05, 2022

Go to field properties -> Format tab, select 'Special' then 'Arbitrary Mask' and input this:

A9A 9A9

To make it all capital letters as 'Validation' script use this:

event.value = event.value.toUpperCase();

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 05, 2022 May 05, 2022

Go to field properties -> Format tab, select 'Special' then 'Arbitrary Mask' and input this:

A9A 9A9

To make it all capital letters as 'Validation' script use this:

event.value = event.value.toUpperCase();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2022 May 05, 2022

Thank you so much !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 26, 2023 Jul 26, 2023

I am already using Custom Format Script to define placeholder/instructional text, and therefore Arbitrary Mask solution above is unavailable to me.

Is there another solution to achieve this result, perhaps a custom validation script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 26, 2023 Jul 26, 2023

You can try something like this as custom format script:

if(event.value)
event.value = util.printx("A9A 9A9", event.value);
else
event.value = "Instructional text";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 26, 2023 Jul 26, 2023

Thanks, i wasnt able to get that to work as i intended.

this is what i am using now:

Custom Format Script

if (!event.value){
event.value = "Click here to enter NAME";
event.target.textColor = color.ltGray;
event.target.display = display.noPrint;
}

else {
event.target.textColor = color.black;
event.target.display = display.visible;
}

 

when i click the field to enter text, i would like it to format as "AA-AAA-AAAA-999". If i clear the field, i would like it to show the "Click here to..." text in grey again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 26, 2023 Jul 26, 2023

In the 'else', add 'util.printx' part, with your formatting.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 27, 2023 Jul 27, 2023

I swear I tried that before I responded? But that did the trick. Perfect, Thank you Ms. Nurani for sharing your skill.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 27, 2023 Jul 27, 2023
LATEST

FYI anyone looking for similar, this was my final solution:

place in Custom Format Script:

 

if (!event.value){
event.value = "Instructional Text";
event.target.textColor = color.ltGray;
event.target.display = display.noPrint;
}

else {
event.value = util.printx("AA-AAA-AAAA-999", event.value);
event.target.textColor = color.black;
event.target.display = display.visible;
}

 

Maybe useful to someone else.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines