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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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;}
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'.
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
Copy link to clipboard
Copied
Share your file if you can and Il take a look.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Here is file with script inside validation:
https://drive.google.com/uc?export=download&id=1d5a1jH6Pd95pjhR5cFNQObnkqUN8vjj5
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;}
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
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
Copy link to clipboard
Copied
Restarted the computer, it works (can write validation script).. thank you
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
Copy link to clipboard
Copied
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;}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you for your suggestion, gives me many ideas I wud like to try Cheers