You are viewing limited content. For full access, please sign in.

Question

Question

Can the 'gap' be removed from custom HTML when a passed value is empty?

asked on August 26, 2022

I have the following custom HTML:

<span name="Customer_Name"></span><br>
<span name="Address"></span><br>
<span name="Address2"></span><br>
<span name="City"></span>, <span name="State"></span>
<span name="Postal_Code"></span>

The values are passed to the HTML span names when the source field triggers the following function:

function mapData(e){
  var value = '';
  
  // radio fields
  if(e.hasClass('dataRadio')){
    value = e.find('.cf-field input:checked').val();
  }
  // input fields
  else {
    value = e.find('.cf-field :input').val() || $(e).find('.cf-field div[type]:eq(0)').html() || '';
  }
  
  // get the variable name of the trigger field
  var name = e.attr('attr');
  
  // update display field value
  $('span[name="' + name + '"]').html(value.replace(/\n/g,'<br>'));
}

Since Address2 is often empty I end up getting a "gap" in the customer address:

So I am looking for a way to tweak this process to essentially ignore Address2 when it's empty.  Thanks in advance for any suggestions.

 

0 0

Replies

replied on August 26, 2022 Show version history

Having a <br> exist after each span will mean there is a line break after every span regardless of if it has contents. I would only have the span objects. Then when you insert a value into a span include a <br> for the line break. This way you only break lines when text is entered.

IE: span.html('Some Text<br>');

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.