Question

How can I link together multiple fields in Acrobat, such that the user can continue to write in the next field when the current field is full? Ideally, pasting data into one field would continue to paste into the next field(s) as well if the pasted string is too long for that field.

In this specific case the fields are for entering an IBAN number in groups of 4 digits because that is the layout used on the paper form that lies under the PDF form fields: IBAN fields

Was it helpful?

Solution

While it is not perfect, you can use the following function as a document-wide function. The only problem is that the cursor is not currectly moved to the correct field when pasting text that spans multiple fields.

Acrobat 9: Advanced > Document Processing > Document JavaScripts
Acrobat 10: Tools > JavaScript > Document JavaScript

function tab_chain(prev_field_name, next_fields) {
    // Move to next field if the current keystroke
    // fills the field. Move to the previous field
    // if the current keystroke empties the field.

    // Pasted data that is too long for the current
    // will be continued into the fields listed in
    // the next_fields array.

    var rest, prev, next, i;
    event.change = event.change.toUpperCase();
    rest = event.changeEx.toUpperCase();
    var merged = AFMergeChange(event);
    //console.println("Name: '" + event.target.name + "'");
    //console.println("Merged: '" + merged + "'");

    if (merged.length === event.target.charLimit) {
        //console.println("Limit: " + event.target.charLimit);
        i = 0;
        prev = event.target;
        next = getField(next_fields[i++]);
        rest = rest.substr(event.change.length);
        while (next !== null && rest.length > 0) {
            //console.println("Rest: " + rest);
            merged = rest.substr(0, next.charLimit);
            rest = rest.substr(merged.length);
            next.value = merged;
            prev = next;
            next = getField(next_fields[i++]);
        }
        // Update focus if previous pasted field is full.
        if (next !== null && merged.length === prev.charLimit) {
            next.setFocus();
        }
    }
    else if (merged.length === 0) {
        getField(prev_field_name).setFocus();
    }
}

Then, call this function as a custom keystroke script under Properties > Format. As the first parameter you pass the previous field in the chain (or the field itself if it is the first). As the second parameter you pass a list of the following fields in the chain. For example if your fields are called IBAN1, IBAN2, ..., IBAN6:

Script for IBAN1: tab_chain("IBAN1", ["IBAN2", "IBAN3", "IBAN4", "IBAN5", "IBAN6"]);
Script for IBAN2: tab_chain("IBAN1", ["IBAN3", "IBAN4", "IBAN5", "IBAN6"]);
Script for IBAN3: tab_chain("IBAN2", ["IBAN4", "IBAN5", "IBAN6"]);
etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top