Keystrak and format for Text Field format
5648 ワード
https://acrobatusers.com/tutorials/formatting_text_.fields
Scrope:All Acrobat versions Skill Level:Intermediate Prerequisites:Famility with Form Fields and the JavaScript environment
Acrobat provides 2 events(script locations)for handing texfield formatitititing.The Keystrak(change)event and the Format event.Together,these events can be used contrtrolboth the format of danterininininininininininininininininthethethethethethetheaaaaaathethethethethethethethetheaaaaaaaaaaathe thethethethethethethethethethethe aaaaaaathethethethethethethethethethethethethethethethethethethetheaaaaaaaaaaaaexamples、are provided in the Formatting Examples.pdf file.
Formatting Examplesdown load Formatting Examples.pdf
The Keystrock Event
The Keystrak is caled in two different situations.First,it is caled for each change made to the field during data entry.Tylially this means for each of the user’s keystrockes,私は、ビットのis also caled when datas s s pasted in to the field from the clipboard.The databeininininininstrered stored isstored inintempororary location and does the real value of the field until the eeeeeeeeeeeeeeeeeether thethethethererererererererererererererererererererererererererererethethethethethethethethethethethethethethethethethethethethethererererererererestststststststinininininininininininininininin...The second situation in which the keystrace event is caled is immediately before the data is comitted to the field value.For convence we'll call this the WillComit event.The Event Object videvides the.eventititititititititititititititititite.Commitititititititititititite.The
These two situations provide us with a way to maipulate the ntered data in two ways.The first allows s s to filtr and replace the dataasitisentered.For example、to garatee the user will will enter a numericvalukekeaaaaaaattttttttttttttttttttttttttttfffffffrererererererererererererererererererererereststststststststststststststststststststststs s s s s s s s s s event return value、event.rc,to false;
The Keystree event that occurs immediatery before the entered value is comitted、the WillComit event、gives the script a final change to reject or changed the entered data.For example、with the prvious ptis ptiteThis number is illegal because you can't have two decimal points in a number.The follwing script corects this problem by using the WillComit event.
Another way to use the Keystrocke event is to replace the input.For example,the following Keystrock script forces all characters entered to up case.
Keystrke filtering and substitions made with the Keystrke event occur before data is comitted and change the real value of the form field.On the other hand,changes made with the Format event happen after the the the migearts Compart change.com.not the field’s value.This is is useful for any number that requires special smbors when displayed to the user,such as currency.For the currency smbol is verimport,but it is also importent for the field value to be a number so it can be used in calculations.The smbol can't t be part of the actual field value.The follo wing Format script prefixes the field valust Breld Bremystal
Scrope:All Acrobat versions Skill Level:Intermediate Prerequisites:Famility with Form Fields and the JavaScript environment
Acrobat provides 2 events(script locations)for handing texfield formatitititing.The Keystrak(change)event and the Format event.Together,these events can be used contrtrolboth the format of danterininininininininininininininininthethethethethethetheaaaaaathethethethethethethethetheaaaaaaaaaaathe thethethethethethethethethethethe aaaaaaathethethethethethethethethethethethethethethethethethethetheaaaaaaaaaaaaexamples、are provided in the Formatting Examples.pdf file.
Formatting Examplesdown load Formatting Examples.pdf
The Keystrock Event
The Keystrak is caled in two different situations.First,it is caled for each change made to the field during data entry.Tylially this means for each of the user’s keystrockes,私は、ビットのis also caled when datas s s pasted in to the field from the clipboard.The databeininininininstrered stored isstored inintempororary location and does the real value of the field until the eeeeeeeeeeeeeeeeeether thethethethererererererererererererererererererererererererererererethethethethethethethethethethethethethethethethethethethethethererererererererestststststststinininininininininininininininin...The second situation in which the keystrace event is caled is immediately before the data is comitted to the field value.For convence we'll call this the WillComit event.The Event Object videvides the.eventititititititititititititititititite.Commitititititititititititite.The
These two situations provide us with a way to maipulate the ntered data in two ways.The first allows s s to filtr and replace the dataasitisentered.For example、to garatee the user will will enter a numericvalukekeaaaaaaattttttttttttttttttttttttttttfffffffrererererererererererererererererererererereststststststststststststststststststststststs s s s s s s s s s event return value、event.rc,to false;
if(!event.willCommit)
event.rc = !isNaN(event.change) || event.change == ".";
By testing the willComit property、the script only processes events caused by user keystrkes.The event.chage properpertyholds the value of the keystrkeor clipboard paste.It isisisproperththththththaat t t t tetested for acceptable aptle inppputdatatathethe inininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininof characters.The Keystree event that occurs immediatery before the entered value is comitted、the WillComit event、gives the script a final change to reject or changed the entered data.For example、with the prvious ptis ptiteThis number is illegal because you can't have two decimal points in a number.The follwing script corects this problem by using the WillComit event.
if(!event.willCommit) {
// Test individual keystrokes and clipboard pastes
event.rc = !isNaN(event.change) || event.change == ".";
} else {
// Test the entire pre-commit value
event.rc = !isNaN(event.value);
}
Returning false from the WillComit event reject s the entered value and abots event processing for that field.This means that the field returns to its previous value and that neither the Valide FormareAnother way to use the Keystrocke event is to replace the input.For example,the following Keystrock script forces all characters entered to up case.
if(!event.willCommit)
event.change = event.change.toUpperCase();
The Format EventKeystrke filtering and substitions made with the Keystrke event occur before data is comitted and change the real value of the form field.On the other hand,changes made with the Format event happen after the the the migearts Compart change.com.not the field’s value.This is is useful for any number that requires special smbors when displayed to the user,such as currency.For the currency smbol is verimport,but it is also importent for the field value to be a number so it can be used in calculations.The smbol can't t be part of the actual field value.The follo wing Format script prefixes the field valust Breld Bremystal
event.value = String.fromCharCode(0x0A3) + event.value;
The apearance of the field is changed so the user always ses the currency smbol prefixed onto the number,but the real value of the field is unchanged.As extremile example of this der,the follect the the the the fillectwinds the the the the the the fieltwint ficrediscriptevent.value = "Blocked";
Another way to use this event is to convey special value information to the user.In the follwing Format script a red“NA”is displayed if the field value is less than or equal to zero.Note that a non-numeric field value will cause the script to fail.The validity of the data is not tested here.It is astromed the field aladreable the ablearsif(event.value <= 0) {
event.value = "NA";
event.target.textColor = color.red;
} else
event.target.textColor = color.black;
Mush more compicated formas are possible by using these events with reglar expressitions.But that’s another Tip.