adding a string based on established value. Removing string on event change

Explorer ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

I am working on a combobox that is one of several inputs that populate a one field. I use the SetFieldValues to achieve this.

if (level.value>=3){
SetFieldValues(event.value)
function SetFieldValues(cName){
if (this.getField("Other Proficiencies").value !=="")
{this.getField("Other Proficiencies").value= this.getField("Other Proficiencies").value += "," + LangProf[cName].prof;}
else
{this.getField("Other Proficiencies").value=LangProf[cName].prof;}}}

My first issue is that I have to recommit the combobox value to trigger the function. I am looking for a way to have it read the value already present and add accordingly without overwritting the target field.  

My second issue is when the value changes, the previous string remains in the field. I don't mind deleting it but if there is a way to do it automatically, it would have multiple applications for my project.

Thanks for reading and also for any help!

TOPICS
Create PDFs, Edit and convert PDFs, JavaScript, PDF forms

Views

119

Likes

translate

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

Most Valuable Participant , Mar 03, 2021 Mar 03, 2021
Use event.change, and check that event.willCommit equals false first.

Likes

translate

Translate

Translate
Most Valuable Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Where did you place the code?

Did you make sure to tick the option to commit the selected value of the drop-down field immediately?

Likes

translate

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
Explorer ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

I have it placed on the combobox under custom keystroke and the value is commited immediately. I just realized if the correct user value is present, and then I switch to any new value, that is when the string will pop up. It seems to ignore the current value and waits for the next value to be selected.   

Likes

translate

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
Most Valuable Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Use event.change, and check that event.willCommit equals false first.

Likes

translate

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
Explorer ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Thank you for the advice! This sounds like the way forward. I will do my reading to see what I can do. 

Is there a way to remove the string after the fact? I was thinking I could just subtract LangProf[cName].prof but that sounds like it would just cancel out rather than undo.

Likes

translate

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
Most Valuable Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

You can simply delete the contents of the field.

Likes

translate

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
Explorer ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

I have tried to implement this advice but cannot seem to wrap my head around it. Considering the code I provided in the original post, how would you amend it with !event.willCommit and event.rc? I don't mean to waste any of your time but the resources I find online are beyond my ken. Thank you for the help you have already given.

Likes

translate

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
Most Valuable Participant ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Just move the code to the Validation event, it's easier...

Likes

translate

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
Explorer ,
Mar 12, 2021 Mar 12, 2021

Copy link to clipboard

Copied

I will try this. Thank you again for the response.

Likes

translate

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