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

Drop-down List to use to change Font in a field

Community Beginner ,
Dec 22, 2021 Dec 22, 2021

Copy link to clipboard

Copied

Hi

I have set out to create a drop-down list "fontSelector"with font names. I have  a Textfield "Text2". I would like to change font of text in "Text2" based on selection of font name in "fontSelector"

I have tried JS in "fontSelector" â†’ Mouse Up

if (event.value == "Courier") {
this.getField("Text2").textFont = font.Cour;
} else if (event.value == "Times") {
this.getField("Text2").textFont = font.Times;
} else if (event.value == "Helvetica") {
this.getField("Text2").textFont = font.Helv;
} else if (event.value == "Times Bold") {
this.getField("Text2").textFont = font.TimesBI;
}else {
this.getField("Text2").textFont = font.Symbol;
}

 

Another approach, below code in the custom calculation in "Text2" field, with export value for selection in dropdown List as TimesBI, Symbol etc

this.getField("Text2").textFont = getField("fontSelector").value;

In both, Text2 is Symbol font, and does not change with change in selection in fontSelector

Thank you for help ..Cheers

 

TOPICS
JavaScript

Views

1.3K

Translate

Translate

Report

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

correct answers 2 Correct answers

Community Expert , Dec 23, 2021 Dec 23, 2021

You should download this demo file:

https://abracadabrapdf.net/file/Menus_deroulants.pdf

 

Capture_53.png

Votes

Translate

Translate
Community Expert , Apr 09, 2022 Apr 09, 2022

Just add itlike this:(example from above script)

var f1 = this.getField("Text2");
var f2 = this.getField("Text3");
switch(event.value){
case "Courier":
f1.textFont = font.Cour;
f2.textFont = font.Cour;
break;}

 

Votes

Translate

Translate
Community Expert ,
Dec 22, 2021 Dec 22, 2021

Copy link to clipboard

Copied

If you use script as Mouse UP you need to change 'event.value' to 'event.target.value'
but even then if you use script as Mouse UP you will have a delay, instead use this as 'Validation script' of dropdown field:

var f = this.getField("Text2");
switch(event.value){
case "Courier":
f.textFont = font.Cour;
break;
case "Times":
f.textFont = font.Times;
break;
case "Helvetica":
f.textFont = font.Helv;
break;
case "Times Bold":
f.textFont = font.TimesBI;
break;
default:
f.textFont = font.Symbol;}

In dropdown field -> properties -> options tab tick 'Commit selected value immediately'.

Just a note for 'Times Bold: 'TimesBI' is Times Bold Italic, Times Bold should be 'TimesB'.

Votes

Translate

Translate

Report

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Thankyou Nesa for looking at my script, I tried, but some how I cant make the script stay in validation box. After saving, â†’reopen, no script 

dropdown field â†’ properties → Validate →run custom script 

any suggestions cheers

Votes

Translate

Translate

Report

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Share your file if you can and Il take a look.

Votes

Translate

Translate

Report

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Hi Attached is file. Also i wud like to change colour of straight lines/ pen arrow etc based the Colour check Boxes

Thank yo for ur help

Votes

Translate

Translate

Report

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

To change annot color depending on checkbox first you need to get annot name, select your annot(example: Line) and press CTRL+J now in console paste this code:
this.selectedAnnots[0].name;
and press Enter to get name, now copy that name and put it into code where says "Your annot name goes here".

EXAMPLE:

if(event.target.value != "Off"){
this.getAnnot(1,"Your annot name goes here").strokeColor = color.blue;}

 

Votes

Translate

Translate

Report

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Thank you Nesa, This works Great. I have manged to create a dynamic Stamp, where I can change the font colour/ font type, and now the box around the text field of the Stamp

I have put this code to modify the text field of Stamp on the first blank page. I have to navigate to stamp folder, make selection, and use the stamp. wondering if cud pin the first blank sheet on the menu bar.

Cheers

Votes

Translate

Translate

Report

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Hi Nesa

 Tried to put validation script in another dropdown List, it does not stay, are any conditions need to be satisfied for it work. Apologies for asking so many Q's

Thank you

Votes

Translate

Translate

Report

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Restarted the computer, it works (can write validation script).. thank you

Votes

Translate

Translate

Report

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 ,
Apr 09, 2022 Apr 09, 2022

Copy link to clipboard

Copied

Hi, This script works great, just wondering how I could change font in more than one text field. (text fields are named "Text2" & "Text3")

Cheers

Votes

Translate

Translate

Report

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 ,
Apr 09, 2022 Apr 09, 2022

Copy link to clipboard

Copied

LATEST

Just add itlike this:(example from above script)

var f1 = this.getField("Text2");
var f2 = this.getField("Text3");
switch(event.value){
case "Courier":
f1.textFont = font.Cour;
f2.textFont = font.Cour;
break;}

 

Votes

Translate

Translate

Report

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

You should download this demo file:

https://abracadabrapdf.net/file/Menus_deroulants.pdf

 

Capture_53.png

Votes

Translate

Translate

Report

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Thank you for your suggestion, gives me many ideas I wud like to try Cheers

Votes

Translate

Translate

Report

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