Skip to main content
Charles Guo
Inspiring
October 31, 2018
Answered

I have a script to change all text fields to read-only but I need it to only change to read-only if all the required fields are completed

  • October 31, 2018
  • 1 reply
  • 389 views

Hello, I have the following script which changes all my text fillable fields into read-only fields.

for(var i = 0; i < this.numFields; i++) {

    var fieldName = this.getNthFieldName(i);

    if (this.getField(fieldName).type == "button" ||

    this.getField(fieldName).type == "signature")

    {

        //console.println(i+":no:"+fieldName);... used in the debugger

    }

    else {

        //console.println(i+":"+fieldName);... used in the debugger

        getField(fieldName).readonly = true;

    }

}

I also have a submit form option which will validate and ensure all required fields are completed.

The issue i'm having is that even if some fields are no completed, by clicking the button it will change all fields to read only, is there a way for my script to only run upon completion of all required fields?

Thank you in advance,

This topic has been closed for replies.
Correct answer Charles Guo

Just an update on this question:

I was able to find this code: thanks to NIKOWA555

var ok = true;

var i = 0;

for (i = 0; i < this.numFields; i++){

try{

var f = this.getField(this.getNthFieldName(i));

if(f.required==true){

if(f.value==f.defaultValue && f.type != 'button' && f.type != 'signature'){

  ok=false;app.alert('Missing Value: '+f.name);

}

}

}catch(ex){};

};

if(ok==true){

for (var i = 0; i < this.numFields; i++){

var f = this.getField(this.getNthFieldName(i));

f.readonly = true;

};

var to = "you@domain.com";

var strUrl = "mailto:"+to+"?subject=TEST&body=TEST&cc=&bcc=";

var submitAs = "PDF";

this.submitForm({cURL: strUrl, cSubmitAs:"PDF"});

};

however this now makes everything read only, can someone help me adjust the code so that it only makes text fields read-only?

1 reply

Charles Guo
Charles GuoAuthorCorrect answer
Inspiring
October 31, 2018

Just an update on this question:

I was able to find this code: thanks to NIKOWA555

var ok = true;

var i = 0;

for (i = 0; i < this.numFields; i++){

try{

var f = this.getField(this.getNthFieldName(i));

if(f.required==true){

if(f.value==f.defaultValue && f.type != 'button' && f.type != 'signature'){

  ok=false;app.alert('Missing Value: '+f.name);

}

}

}catch(ex){};

};

if(ok==true){

for (var i = 0; i < this.numFields; i++){

var f = this.getField(this.getNthFieldName(i));

f.readonly = true;

};

var to = "you@domain.com";

var strUrl = "mailto:"+to+"?subject=TEST&body=TEST&cc=&bcc=";

var submitAs = "PDF";

this.submitForm({cURL: strUrl, cSubmitAs:"PDF"});

};

however this now makes everything read only, can someone help me adjust the code so that it only makes text fields read-only?