Intro:
This is a problem that I have had on a few of my forms, and one that I especially needed to solve for a couple of reasons.
Labels are, as they sound, just that... labels. They are ignored in the Form Data and any Repeating Section xml that they are a part of. This is makes them uniquely awesome at displaying data that is read-only, but because there is no obvious way of changing those values once they have been set, it can prevent people from using them and instead revert to something like a Calculated Control which could potentially pollute your Form Data xml or Repeating Section xml (if you ever use those things. If you don't, then it wouldn't matter! ).
Before continuing to the below solution, it should be noted that it is dependent on JavaScript. If you are unable to use JavaScript in your environment, for whatever reason, then you might want to consider a different approach (or even a Calculated Control as you mentioned), as JS makes life a lot easier.
For those who can continue...
My Environment:
Sharepoint Version: 2016
Browser: Google Chrome Version 61.0.3163.91 (Official Build) (64-bit)
The Solution:
We can solve this by abusing, err, I mean, utilizing, the Nintex Form Rule system. Because Formatting Rules are evaluated during the form building phase for both a New Form, a form that is being Edited, or a Form that is being Viewed, they are a great way to kill several birds with one stone.
On your test form, place some test controls as shown below.
The Form Controls:
The test controls will consist of (2) Label Controls, (1) Choice Control, and (1) Input Control.
The Choice Control should be configured as follows:
Make sure that you name your control the same as it is shown here ('control_AnimalChoice') otherwise, you'll have a bad day.
The Rule:
Selecting the Label Control that you'd like to change (in this case, the one that reads 'How Many Animals:'):
Add a Formatting Rule by clicking the Add Rule button in the Navigation Ribbon and name it whatever you'd like (or not at all). I have called mine "Label Changer":
Note: I have selected the Disable option for this rule because I want it to be disabled when I have nothing selected, to give even more feedback to the user.
For the Condition Field, click the Add Reference (aka: f(x)) button, and add the following code. BE SURE TO REPLACE THE FINAL INPUT OF 'control_AnimalChoice' WITH THE ACTUAL CONTROL REFERENCE (which will show as a red link).
(function (sourceContext, formControlCall, selectedAnimal) {
"use strict";
var formControlID = formControlCall.split("'")n1] || "";
var targetControl = sourceContext.find("nformcontrolid='" + formControlID + "'].nf-filler-control");
var targetLabel = targetControl.find("label");
var noAnimalSelected = !selectedAnimal;
var labelText = (noAnimalSelected) ? "Please Select An " : "How Many ";
selectedAnimal = (noAnimalSelected) ? "Animal" : selectedAnimal;
if (targetLabel.length > 0) {
targetLabel.text(labelText + selectedAnimal + ":");
}
return (noAnimalSelected);
}(sourceContext, "{Control:Self}", control_AnimalChoice));
It will look like this in the Rule's Condition Editor:
The Result:
Now when you run the form, based on what you have selected in the Choice Control, a different label will be generated, and if nothing is selected, our label will be grayed out to indicate that something is amiss!
Note: I have added an extra rule that also disables the Input Control as that would normally be how you'd want it to look in real life.
Default Value:
Cows Selected:
Donkeys Selected:
Chickens Selected:
Pigs Selected:
Ducks Selected:
Outro:
I hope that this helps you to achieve what you're trying to do inside of your Form. It's not a particularly obvious way of approaching it, but it's the best and most flexible way that I have found of solving it (for what I want to do).
If you have any other questions about this solution, feel free to ask.
Thank you for the replies! Though, after I sent the note, I discovered the formula I needed.
The above is pretty complex for me (a beginner at this stuff). So I kept it simple. I deleted the label and created a calculated field. In the formula field, I wrote this function: If(LOB=='Life','Policy #','Contract #')
And added more to it and broke out each Insurance term separately (Life, Annuity, Car, Home, etc.)