Wrapping Text Calculated Field
-
I need help resolving an issue with wrapping text in a calculated field. I have tried using the suggestion given in another thread mentioning wrapping text by using a Content HTML field, but have been unsuccessful. My calculation is as follows: If age less than x, return y and so forth. The function works properly but the one line limitation doesn’t allow the entire sentences to be shown. Here is the function:
(function(){ if(fieldname23 < 2) return "First sentence here"; if(fieldname23 < 8) return "Second sentence here, and an explanation to go along with it, as well as a suggestion to possible solutions to the problem."; if(fieldname23 < 11) return "Third sentence here"; if(fieldname23 >= 12) return "Fourth sentence here"; })()
The issue is with the Second sentence as it is long.
-
Hello @codepeople
Unfortunately that doesn’t work. I need to select the HTML field in the dependencies for the dropdown menu so that the result is displayed. If I select the same HTML field for several options, the same result displays (fieldname37), even if I select the option that should display results for fieldname 36, fieldname 37 is displayed. If I select the calculated fields in the dependencies in the dropdown menu, even if the function with var result is placed in the equation section, nothing displays after the option is selected from the dropdown menu.
And when I had the HTML content field selected in one of the dependencies from the dropdown menu, the results would display, but still would not wrap.
I even made a new HTML content field, and tried naming another variable in a different fieldname trying to then direct another option to that particular HTML field, yet it seemed that it still displayed results for the first option that was set up. Option A> fieldname 44 (HTML content). Option B>Fieldname 45 (HTML content). Option A would always display results for Option B. If I set u Option A>fieldname36 and Option B>fieldname37, no results would display.
Please help.
Hello @codepeople
Unfortunately that doesn’t work. I need to select the HTML field in the dependencies for the dropdown menu so that the result is displayed. If I select the same HTML field for several options, the same result displays (fieldname37), even if I select the option that should display results for fieldname 36, fieldname 37 is displayed. If I select the calculated fields in the dependencies in the dropdown menu, even if the function with var result is placed in the equation section, nothing displays after the option is selected from the dropdown menu.
And when I had the HTML content field selected in one of the dependencies from the dropdown menu, the results would display, but still would not wrap.
I even made a new HTML content field, and tried naming another variable in a different fieldname trying to then direct another option to that particular HTML field, yet it seemed that it still displayed results for the first option that was set up. Option A> fieldname 44 (HTML content). Option B>Fieldname 45 (HTML content). Option A would always display results for Option B. If I set u Option A>fieldname36 and Option B>fieldname37, no results would display.
Hello @kapdev
Actually, there are multiple alternatives, but they depend on your form structure. You can insert multiple “HTML Content” fields configured as dependents as you did with the calculated fields. But in this case, you must enter the div tags in their contents with different class names, like:
<div class="result-here-1"></div>
<div class="result-here-2"></div>
<div class="result-here-3"></div>
And populate the corresponding tag from the different equations:
jQuery('.result-here-1').html(result);
jQuery('.result-here-2').html(result);
jQuery('.result-here-3').html(result);
Best regards.
what should I place after return?
Currently it reads:
jQuery(‘.result-here’).html(result)
return result;Should it read jQuery(‘.result-here-1’).html(result)
return result; ?I have tried renaming the variable result for example
fieldname 36 would correspond to var A
HTML:
<div class=”result-here-A”></div>
(function(){ var A= ''; if(fieldname2 < 16) return "First"; if(fieldname2 <= 30) return "Second"; if(fieldname2 > 40) return "Third"; jQuery('.result-here-A').html(A) return A; })()
But that didn’t work either. Nothing populates on the page when the option is selected.
Also, I don’t know if this will work because even though it works for one field only (nauseas y vómitos/onsetron), it doesn’t wrap text when I view the page on my phone.
So I guess the first issue to solve would be wrapping text. Afterwards, figuring out how to apply it to multiple fields.
Hello @kapdev
I implemented one of your equations. You must repeat the process with the rest of them.
If you insert “return” instructions into the conditional statements, the equation stops its evaluation and returns the value without reach the code that displays the value in the “result-here-A” tag.
This equation must be edited as follows:
(function(){ var A= ''; if(fieldname2 < 16) A = "First"; else if(fieldname2 <= 30) A = "Second"; else if(fieldname2 > 40) A = "Third"; jQuery('.result-here-A').html(A) return A; })()
As you can see, I’ve assigned the value to the A variable and included only one return instruction after displaying the result into the “result-here-A” tag.
Best regards.
Thank you! Changing return for A worked! The results display. However, if you view the results on a mobile phone, the text doesn’t wrap. Even though the calculated field is hidden from public view, the results display inside a box, with the title of the hidden field. The results are contained in one line only, therefore, it still doesn’t wrap the text. I am sending the link of the sister page so you can see the results on a phone if available. You may choose nauseas/modifical or nauseas/onsetron to see what I am referring to.
Now the only issue is it still doesn’t wrap the text. How can I fix that?
Hello,
I’m sorry, but I’ve responded to this question in many entries.
The idea would be to display the results into the div tags and not into the calculated fields. The calculated fields are input tags, and the input tags do no wrap texts (HTML Standard).
Best regards.
I understand. I feel you are being generous with your time. You have responded this many times, I have also asked this many times. I apologize. I feel I haven’t been able to explain my question properly. The issue is on a mobile device. In this case using iOs and Safari.
I have created an HTML content fields with <div class=”result-here-A”></div>, and others using B,C, etc
I have inserted the function that names and assigns value to the variable in the Set equation in a Calculated Field, followed by jQuery(‘.result-here-A’).html(A)
return A; (substituting B, C and so forth)On a computer, the results display without the Calculated Field Title and without the box. It works. On a mobile, it doesn’t. Therefore, the text does not wrap. On a mobile, it ignores the Hide from public view instruction and ignores the HTML content altogether.
I don’t know if I need to use “use strict” or if there is something else going on.
Hello @kapdev
Please, let me know the id of the form you are editing (the form 6 or 7), and the values you are entering and selecting on every field.
Best regards.
I am editing the cloned field. Field number 7. I am entering the following:
The only two fieldnames I have worked this on are fieldnames 36 and 37. The HTML contents for them are Fieldname 60 (corresponds to fieldname 37) and fieldname 61 (corresponds to fieldname 36).
The main dropdown menu is fieldname45 > nauseas > fieldname26 > modifical > fieldname61
Fieldname61 (HTML):
<div class=”result-here-modifical” ><div>
Fieldname36:
(function(){ var modifcal= ''; if(fieldname2 < 16) modifical ="No se recomienda este medicamento por no poderse partir la tableta"; else if(fieldname2 <= 30) modifical = "UNA TABLETA de 4 mg vía oral (por boca) una única vez"; else modifical ="DOS TABLETAS de 4 mg vía ORAL (por boca) una única vez"; jQuery('.result-here-modifical').html(modifical); return modifical; })()
The other one is Fieldname45 > nauseas > fieldname26 > onsetron > fieldname60
Fieldname60 (HTML):
<div class=”result-here-modifical” ><div>
Fieldname37:
(function(){ var onsetron = ''; if(fieldname2 < 10) onsetron = "No se recomienda este medicamento por no poderse partir la pastilla"; else if(fieldname2 <= 40) onsetron = "1 tableta BUCODISPERSABLE de 4 mg vía oral, una sola dosis. Dejar que se disuelva en la boca. Puede repetir la dosis en 12 horas en caso necesario"; else onsetron = "2 tabletas BUCODISPERSABLES de 4 mg vía oral, una sola dosis. Dejar que se disuelvan en la boca. Puede repetir la dosis en 12 horas en caso necesario"; jQuery('.result-here-onsetron').html(onsetron); return onsetron; })()
Thanks
Hello @kapdev
I’ve tested your form 7 in the mobile:
And the text is wrapped correctly. Please, look at the screenshot below:
Best regards.
- This reply was modified 3 years, 7 months ago by codepeople.
You are right… I guess calculated fields is not compatible with my theme …?
How can I send you a screen shot of my mobile? If you go to the page directly using the link I sent you, on your mobile, you can see what happens with the text on the actual page without typing /?cff-form=7.Also, for protection, would you please delete the previous post with the link and screenshot?
Thanks
Hello @kapdev
I’m sorry, but I don’t know what is the URL to the page where you have the form 7
Best regards.
Hello @kapdev
Your problem is different, you don’t see the changes in the form because you are visiting a cached version of your website generated by LiteSpeed Cache
<!-- Page generated by LiteSpeed Cache 3.6.4 on 2021-04-26 03:35:28 -->
Please, purge your website’s cache.
Best regards.
WOW!!!!!!!!!
THANK YOU THANK YOU THANK YOU!
- The topic ‘Wrapping Text Calculated Field’ is closed to new replies.