• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Removing linebreaks from a textfield

Contributor ,
Jul 10, 2022 Jul 10, 2022

Copy link to clipboard

Copied

SmartSelect_20220711-023458_WhatsAppBusiness.jpg

ā€ƒ

This field (Summary of Services) generated from many textfields. I mean I can't access to delete the empty lines manually.

So if there is a code or a way I can delete these empty lines this will be great.

Ans this is the script I used:

 

// Get the field values, as strings

var s1 = getField("Hob.1").valueAsString;

var s2 = getField("Hob.2").valueAsString;

var s3 = getField("Hob.3").valueAsString;

var s4 = getField("Hob.4").valueAsString;

var s5 = getField("Hob.5").valueAsString;

var s6 = getField("Hob.6").valueAsString;

var s7 = getField("Hob.7").valueAsString;

var s8 = getField("Hob.8").valueAsString;

var s9 = getField("Hob.9").valueAsString;

var s10 = getField("Hob.10").valueAsString;

var s11 = getField("Hob.11").valueAsString;

var s12 = getField("Hob.12").valueAsString;

var s13 = getField("Hob.13").valueAsString;

var s14 = getField("Hob.14").valueAsString;

var s15 = getField("Hob.15").valueAsString;

var s16 = getField("Hob.16").valueAsString;

var s17 = getField("Hob.17").valueAsString;

var s18 = getField("Hob.18").valueAsString;

var s19 = getField("Hob.19").valueAsString;

var s20 = getField("Hob.20").valueAsString;

 

// Combine values, separated by a space

 

event.value = s1+ "\n" + s2+ "\n" +s3+ "\n" +s4+ "\n" +s5+ "\n" +s6+ "\n" +s7+ "\n" +s8+ "\n" +s9+ "\n" +s10+ "\n" +s11+ "\n" +s12+ "\n" +s13+ "\n" +s14+ "\n" +s15+ "\n" +s16+ "\n" +s17+ "\n" +s18+ "\n" +s19+ "\n" + s20;

 

The line breaks happened because of some empty fields.

 

Thank you

TOPICS
JavaScript , PDF forms

Views

2.2K

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 3 Correct answers

Community Expert , Jul 10, 2022 Jul 10, 2022

Add this at the end of your code:

 

event.value = event.value.replace(/\n+/g, "\n");

Votes

Translate

Translate
Community Expert , Jul 11, 2022 Jul 11, 2022

You will need a different kind of script to do all of that. Basically, you need to check the value of each field, before adding it to the final string. So something like this:

var s = "";
var lineCounter = 0;
var s1 = getField("Hob.1").valueAsString;
if (s1) {
	lineCounter++;
	s+=lineCounter+". Local Website ($"+s1+"/mo)\n";
}
var s2 = getField("Hob.2").valueAsString;
if (s2) {
	lineCounter++;
	s+=lineCounter+". National Website ($"+s1+"/mo)\n";
}
// etc.
event.value = s;

 

Votes

Translate

Translate
Community Expert , Jul 30, 2022 Jul 30, 2022

In Hob.9, for example, use this code:

 

 

// Get the field values, as strings
var z1 = getField("qHob.9").valueAsString;
var z2 = getField("Q_Hob_9").valueAsString;
// Combine values, separated by a space, if not empty
if (z1=="" || z2=="") event.value = "";
else event.value = z1 + "   " + z2+ "X";

 

Votes

Translate

Translate
Community Expert ,
Jul 10, 2022 Jul 10, 2022

Copy link to clipboard

Copied

Add this at the end of your code:

 

event.value = event.value.replace(/\n+/g, "\n");

Votes

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
Contributor ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

Thank you very much, it's working

SaherNaji_0-1657523865964.png

Could we add another code to number the lines?

for exampel: 

1. Local Website ($390/mo)
2. National Website ($495/mo)
3. 10 Products ($690/mo)
4. 100 Products ($750/mo)

Votes

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
Contributor ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

I found a solution for numbering the list of services, by using this code:

var myVar = 0;

if(event.value != "") {

event.value = event.value.split(/[\n\r]/g).map(function(a){return (myVar = myVar + 1)+") " + a}).join("\n");

}

but I have a problem with the first line

in both cases if I give it a numbeing format or without it, without number it appears as an empty line at the first.

 

SaherNaji_0-1657525758004.png

Votes

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
Community Expert ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

You will need a different kind of script to do all of that. Basically, you need to check the value of each field, before adding it to the final string. So something like this:

var s = "";
var lineCounter = 0;
var s1 = getField("Hob.1").valueAsString;
if (s1) {
	lineCounter++;
	s+=lineCounter+". Local Website ($"+s1+"/mo)\n";
}
var s2 = getField("Hob.2").valueAsString;
if (s2) {
	lineCounter++;
	s+=lineCounter+". National Website ($"+s1+"/mo)\n";
}
// etc.
event.value = s;

 

Votes

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
Contributor ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

Thanks for the reply, I think it's very close to what I'm lookin for,

I'm not sure if it's okay to share my document here or not,

anyway this is my document attached, I prefer to take a look please

Thanks

Votes

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
Community Expert ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

It's OK to share it, of course, but what's your specified question about it?

Votes

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
Contributor ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

The same question, I would love to fix the 'Summary of Services' textfield to auto number the list, and remove the prefix line preak before the first line.

I shared to document, to not waste your time, and help me with the required code, I don't have enought knowledge in JavaScripts

Thanks again 

Votes

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
Contributor ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

@try67 

 

Thanks Thanks Thanks

working very well, I just did minor edit

Best,

Votes

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
Contributor ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Hello again

Thanks for the previous reply, every thing was great.

I updated the form little bit, but I faced this small problem

SaherNaji_0-1658788107974.png

Fields 9, and 10 appears autmaticlcly by defult

Could you please take a look at the form, and guide me

the form is attached

thanks a lot for that

Best Regards

Votes

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
Community Expert ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Check-boxes always have a value. When they are not ticked that value is "Off".

So you need to change all of the lines of this type:

if (s1) {

To:

if (s1!="Off") {

Votes

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
Community Expert ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Sorry, I didn't notice the hidden fields... Disregard the above comment.

Votes

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
Community Expert ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

The issue is with the code of (some of) the hidden fields. For example, under "Hob.16" the code is:

event.value = this.getField("cHob.1").value == "Off" ? "" : "Retargeting ($550/mo)";

It should refer to "cHob.16", I'm presuming, not "cHob.1"...

Review all of these codes and make sure they are correct.

Votes

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
Community Expert ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

It might be a good idea to make those fields visible, so you could see their values and could debug them more easily... Doing so I found out that the two X's come from Hob.9 and Hob.10, where you have scripts that add them, regardless of whether or not the other fields are empty, which results in them always being added to the summary.

Votes

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
Contributor ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

Actually Yes, it's becase of the scripts related to Hob.9 and Hob.10

Could we add if function somewhere to add the "X" only if the Quantity fields are not empty?

Votes

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
Contributor ,
Jul 30, 2022 Jul 30, 2022

Copy link to clipboard

Copied

SaherNaji_0-1659170629490.png

Hello,

I hope you are doing well,

I tried hundredws of ways to fix it but I couldn't

I only need to change the code here in Hob.9 and Hob.10, to give me the quantity without adding new fields.

every thing is working well, from Hob.1 to Hob.21, but I need to change the code little bit in Hob.9 and Hob.10 to recognize the quanitity

Take a look at the attached file please, I checked all of the checkboxes, except 9 and 10

 

Best Regards

Tnanks in advance

 

Votes

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
Community Expert ,
Jul 30, 2022 Jul 30, 2022

Copy link to clipboard

Copied

In Hob.9, for example, use this code:

 

 

// Get the field values, as strings
var z1 = getField("qHob.9").valueAsString;
var z2 = getField("Q_Hob_9").valueAsString;
// Combine values, separated by a space, if not empty
if (z1=="" || z2=="") event.value = "";
else event.value = z1 + "   " + z2+ "X";

 

Votes

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
Contributor ,
Jul 30, 2022 Jul 30, 2022

Copy link to clipboard

Copied

LATEST

Thank you very much

Working 100%

Votes

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
Contributor ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

Thanks for that, I fixed it

Votes

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