Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Make read only if certain text "N/A" is in text box

New Here ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Hi, 

 

I have a big checklist for work where I have combined multiple checklists and have put together a way for a dropdown to N/A inapplicable items.  This is due to what I've been able to put together from this community, thank you!  What I'd like is for each item to be marked as read only with an if then statement

 

var ProgramList = {

//RIC and FC
Assignment:{

ADR: "", AF24: "N/A", Transcripts: "N/A", Resume: "N/A", DD2088: "N/A",
PSRecords: "", BC: "", SSC: "",
IMT70: "N/A", PRC: "", DD785: "N/A", DD368: "N/A", Waiver: "",
NameChange: "N/A", DD2983: "N/A", DL: "", Marriage: "",
Divorce: "", ABIOSP: "N/A",
AF56: "N/A", SecurityClearance: "", DD369: "", DD2807: "",
ApprovedMedical: "", AFOQT: "N/A", AF1288: "", OASOUs: "",

etc....

 function SetFieldValues(ListItem) { 
    // Populate fields with values from the List Item Object 
    // RIC
    this.getField("RIC1").value = ProgramList[ListItem].ADR;
    this.getField("RIC2").value = ProgramList[ListItem].AF24;
    this.getField("RIC3").value = ProgramList[ListItem].Transcripts;
    this.getField("RIC4").value = ProgramList[ListItem].Resume; 
    this.getField("RIC5").value = ProgramList[ListItem].DD2088; 

etc...

 

I think the easiest way would probably be to use this snippet I got

for (var i = 0; i < this.numFields;
     i++) {
  // process each field name;
  oField = this.getField(this.getNthFieldName(i)).readonly = true;}

but I need to format it so that it only makes the fields that say N/A readonly

 

Thank you for your help, there is such a great wealth of knowledge in this forum.

TOPICS
JavaScript

Views

67

Likes

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 1 Correct answer

Adobe Community Professional , Jul 01, 2021 Jul 01, 2021
There's no need to scan the entire set of fields. You just need to modify those that are set in your code. So you can use something like this: for (var i=1; i<=5; i++) { var f = this.getField("RIC"+i); f.readonly = (f.valueAsString=="N/A"); }

Likes

Translate

Translate
Adobe Community Professional ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

There's no need to scan the entire set of fields. You just need to modify those that are set in your code.

So you can use something like this:

 

for (var i=1; i<=5; i++) {
	var f = this.getField("RIC"+i);
	f.readonly = (f.valueAsString=="N/A");
}

Likes

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
New Here ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

Thank you, I'm sorry I'm not very good at this.  I just got an udemy course to help me learn javascript.

 

I assumed that I could change i<=5 to i<=62 because that's how many fields I have but it didn't work.  As of right now it will skip up to the 5th line with the i<=5 but is there something special I need to do to get it to go through all 62 lines of the checklist like that?

 

Thank you, sorry again for not understanding.

Likes

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
New Here ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

Actually, it does work by just changing to 62, some of the fields don't work correctly and it must be because i have a space or something in there.  Thank you for your help!

Likes

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
New Here ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

Hi sir or ma'am, thank you for this response.

 

Since the "N/A"s are being pulled via a dropdown, how would I remove the readonly from the fields when a different dropdown is pulled?

 

I assumed this would work 

for (var i = 0; i < this.numFields;
     i++) {
  // process each field name;
  oField = this.getField(this.getNthFieldName(i)).readonly = false;}

 

I placed that above the 

 

for (var i=1; i<=5; i++) {
	var f = this.getField("RIC"+i);
	f.readonly = (f.valueAsString=="N/A");

assuming that it would reset all fields to editable and then run your code but it seems to reset all of the fields and then disregard the look for "N/A"s and make the readonly.

 

I then thought to make the turn off readonly for all fields a function and that should work but it didn't.  Thank you again, any guidance is much appreciated.  Thank you!

Likes

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
Adobe Community Professional ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

I'm sorry, I don't understand why you did that. The script I provided will set the RIC fields as read-only when their value is "N/A" and change them back to be editable when it's not (although I'm not sure how that would happen, exactly, as the user can't change the value of a read-only field directly)... Isn't that what you wanted?

Likes

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
New Here ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

LATEST

Your code is 100% perfect, I put the code at the top previously and then realized that everything is blank at that point so I moved it to the bottom and it works flawlessly.  Stay tuned for more newbie laughs coming your way courtesy of me.  Thank you for your help again.

Likes

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