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

Question

Question

Can a variable be used as a Field label in a form?

asked on March 31, 2023

While the functionality appears to be there, I can't seem to make the variable name show up as the label field from a lookup field - There is definitely a value in it...

Read a few posts where others tried, but didn't see any indication of success. Does this feature even exist?

 

thanks!!

What I tried:

<span data-bind-attr="ENGLISH_LABEL">{/dataset/MEMBER_ID}</span>

and

{/dataset/MEMBER_ID}

 

Don't work

0 0

Replies

replied on March 31, 2023 Show version history

I've done this kind of thing with Javascript before.

This works on Classic Designer Version 11.0.2212.30907:  

$(document).ready(function() {
  
  //Save the original label from the destinationValue field
  //so after it is changed, we can revert to it later if needed.
  var destinationValueOriginal = $('.destinationValue').find('.cf-label').find('span').find('span').first().text();
  
  //When the form loads, take the value from sourceValue field
  //and load it as the label on the destinationValue field.
  //This only happens if the sourceValue is not blank (was 
  //populated from a prior task).
  var newLabel = $('.sourceValue input').val();
  if(newLabel != '') {
    $('.destinationValue').find('.cf-label').find('span').find('span').first().text(newLabel);
  }
  
  //When the value of the sourceValue field is changed, update 
  //the destinationValue field to use the sourceValue as the label.
  $('.sourceValue input').change(function() {
    var newLabel = $(this).val();
    if(newLabel != '') {
      $('.destinationValue').find('.cf-label').find('span').find('span').first().text(newLabel);
    }
    else {
      $('.destinationValue').find('.cf-label').find('span').find('span').first().text(destinationValueOriginal);
    }
  });
  
  
});

 

 

 

EDIT TO ADD: Note that Javascript above works on the active version of the form, but not the read-only version (or the version archived to the repository) - because     $('.sourceValue input').val()     returns undefined in the read-only version.  If you need this to work in the read-only version, we have to tweak the code to work in that setting.

 

ADDITIONAL: And here is Javascript for the New Designer (tested that this works on New Designer Version 11.0.2212.30907): 

//Reference the two fields by class name:
var sourceField = LFForm.findFieldsByClassName('sourceValue')[0];
var destinationField = LFForm.findFieldsByClassName('destinationValue')[0];

//Save the original label from the destinationValue field
//so after it is changed, we can revert to it later if needed.
//There doesn't appear to be a getFieldSettings interface in
//the LFForm object, so this is being hardcoded here instead 
//of being retrieved from the field.
var destinationValueOriginal = 'Single Line (has Class: destinationValue)';
LFForm.changeFieldSettings(destinationField, {label: 'xxxxxxx'});

//When the form loads, take the value from sourceValue field
//and load it as the label on the destinationValue field.
//This only happens if the sourceValue is not blank (was 
//populated from a prior task).
var newLabel = LFForm.getFieldValues(sourceField);
if(newLabel != '') {
  LFForm.changeFieldSettings(destinationField, {label: newLabel});
}
  
//When the value of the sourceValue field is changed, update 
//the destinationValue field to use the sourceValue as the label.
LFForm.onFieldChange(function() { 
  var newLabel = LFForm.getFieldValues(sourceField);
  if(newLabel != '') {
    LFForm.changeFieldSettings(destinationField, {label: newLabel});
  }
  else {
    LFForm.changeFieldSettings(destinationField, {label: destinationValueOriginal});
  }
}, sourceField);

 

2 0
replied on April 3, 2023

Hi Dominique, a variable can be used for a Field Label but the caveat being that the value must already be in the field when the form loads. In the case of a Lookup, the forms loads, then the Lookup is completed, which is why you need to use Javascipt to push the value to the field.

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

Sign in to reply to this post.