i have 3 fields:
- 1 dropdown, that contains several rows of data, like this "100001 | Product 1 | 23,4"
- 1 textfield, that should take only the value "100001" from the selected string in the dropdown-menu
- 1 textfield, that should take only the value "23,4" from the selected string in the dropdown-menu
The user selects the row/string from the dropdown-menu and then the other values should be automatically selected depending on the string.
Is this possible and how it could be done?
Help much appreciated : )
Solved! Go to Solution.
Views
Replies
Total Likes
If the number is a decimal, try changing the field to a decimal type rather than a numeric type (although it should probably work anyway). Also, check the display pattern to make sure it's set to display the decimal digits.
What's your locale set to?
Views
Replies
Total Likes
There are lots of ways to do this, based on whether you want to use FormCalc or javascript scripting and which functions you want to use. I've attached a javascript example. There is a dropdown list on the form that's initialized to a few values similar to what you included in your question. The script is in the change event of the dropdown and looks like this:
var parts = xfa.event.newText.split('|');
Part1.rawValue
= parts[0].replace(/^\s+|\s+$/g, "");
Part3.rawValue
= parts[2].replace(/^\s+|\s+$/g, "");
The first line takes the full string that selected in the dropdown and splits it into an array of three strings using the javascript string.split() function. It will split the string into substrings based on the '|' delimiter. The other two lines store the values of the first and third substring into the two text fields. The .replace(/^\s+|\s+$/g, "") stuff trims the spaces from the left and right of each substring, since your example had spaces around the '|' that get included in the substrings.
Thank you, i will try this tomorrow. I will add the stars after this : )
Views
Replies
Total Likes
Can't get the code working (the sample works ok) when i try to apply it to my form.
Here's the codes: Part1.rawValue = parts[0].replace(/^\s+|\s+$/g, "");
Part3.rawValue = parts[2].replace(/^\s+|\s+$/g, "");
If i understood correctly, the Part1/Part3 are the fields the values parts[0]/parts[2] should be copied to?
For example value: "100001 | Product 1 | 23,4"
Part1/Part3 = destination fields
parts[0] = 10001
parts[2] = 23,4
Is this correct?
(sorry for my newbie questions : )
Views
Replies
Total Likes
I think you have it right. Make sure of the following:
If you still have problems, please post the form if possible.
Thanks for the help, i just can't get it working. I changed the dynamic and other settings.
I made a demo of my try (attached: Tester.pdf)
I also change the Part* values to "Field", because i need/want to know how the code works, so i can apply to new forms.
Thanks for the patience : )
Views
Replies
Total Likes
The script should read as follows:
var parts = xfa.event.newText.split('|');
Field1.rawValue
= parts[0].replace(/^\s+|\s+$/g, "");
Field3.rawValue
= parts[2].replace(/^\s+|\s+$/g, "");
The selected text is being split up and stored into the variable 'parts' as an array of strings. After the first line is executed you will have:
parts[0] = '100001 '
parts[1] = ' Product 1 '
parts[2] = ' 1,1'
So, when you store the results into your fields you need to use parts[] as your source of the data.
Views
Replies
Total Likes
Yes, now i got it working. Only one problem.
The string i have has 5 different values (Product 1 | 100001 | 5 | 7 | 23,40)
I understand that if i want a different value (for example the last one), i enter = parts[4].replace and it chooses the last one (5th)
The problem is when the value is 23,40 it show only value 23,00, so the decimals make the error somehow?
The destination values are Numeric Fields
Views
Replies
Total Likes
If the number is a decimal, try changing the field to a decimal type rather than a numeric type (although it should probably work anyway). Also, check the display pattern to make sure it's set to display the decimal digits.
What's your locale set to?
Views
Replies
Total Likes
When i set the destination fields format to Text Field the value comes out ok, without problems.
When the destination field is set to Numeric Field/Decimal Field the value doesn't come out at all, just 0,00 (if the Stringvalue is with decimals), but if the Stringvalue is in full numbers, the value comes out ok.
The Locale doesn't make a dirrerence.
Could the problem be var parts = xfa.event.newText.split('|'); ? Is there a way to make a newText split for number and not for Text? Because both the values are number (1 full number and 1 with 2 decimals)
Views
Replies
Total Likes
Got the code working, i changed the Destination Field to Decimal Field and most importantly, i changed the dropdownList data (the last value) to be divided with . not with , (for example 24.0), then the total value shows up correct in the destination field (= 24,0)
Thank you for your help, stars added
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies