Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Mar 03, 2021 Mar 03, 2021

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
1.1K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 03, 2021 Mar 03, 2021

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

View solution in original post

Translate
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
Community Expert ,
Mar 03, 2021 Mar 03, 2021

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?

Translate
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

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.   

Translate
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
Community Expert ,
Mar 03, 2021 Mar 03, 2021

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

Translate
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

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.

Translate
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
Community Expert ,
Mar 03, 2021 Mar 03, 2021

You can simply delete the contents of the field.

Translate
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

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.

Translate
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
Community Expert ,
Mar 11, 2021 Mar 11, 2021

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

Translate
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
LATEST

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

Translate
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