Variable Label Names - How can I change a field label on the form based on another value in the form
Original Post by Sandy (Imported from Ardevia Forum)
Hi,
Hoping you can help...
Is it possible to change a field label on a form dependant on a value in another field on the form.
E.g. I have a file on the form that when I select particular employment types, I need the field label to read 'Base Salary', when I change to a different employment type, I need the same field to read 'Total Salary Package'.
Thank You
Sandy
-
Original Post by Andrii Berezovskyi (Imported from Ardevia Forum)
Hello Sandy
The easiest way to do this is use single line of text field as label in horizontal group and set initial and calculated expression which will be based on values from dropdown.
Please perform next steps:
1) Add Horizonatl Group on your form, and after that add two Single Line of text fields inside this horizontal group. Clean label for first input. And set Only display checkbox (in ribbon) into checked. See screenshot
2) Add initial and calculated expression for this dynamic label field which will be based on values from dropdown. See screenshot for initial expression .See screenshot for calculated expression .
3) Save form , try add new item , try change dropdown value, label will dynamically change its name
Initial Value Expression Code:
if([[EmployeeTypeDropdown]]=="EmployeeType1"){
return "Label for EmployeeType1";
}Calculated Value Expression Code:
if([[EmployeeTypeDropdown]]=="EmployeeType1"){
return "Label for EmployeeType1";
}
if([[EmployeeTypeDropdown]]=="EmployeeType2"){
return "Label for EmployeeType2";
}0 -
Original Post by Sandy (Imported from Ardevia Forum)
Hi Andrii,
That worked perfectly for when I wanted to change field labels on the main list, but now I am needing to do this for a couple of the columns in one of my sub-lists.
Can this be done?
Thanks
Sandy0 -
Original Post by Liliia (Imported from Ardevia Forum)
Hi Sandy,
Yes, you can change field labels in sub-list as well. For this add calculated expression below on your choice field (e.g.'EmployeeTypeDropdown') with expresison type = 'Function Code':
Code:
var val = [[EmployeeTypeDropdown]] == 'EmployeeType1' ? 'Label for EmployeeType1':'Label for EmployeeType2'; jQuery('.ard-sublist-webpart[ard-webpart-id="<Your_ID>"] .ms-listviewtable.ms-listviewgrid>tbody>tr.ms- viewheadertr>th:nth-child()').find('div[colid="coreContent"]:first').text(val); return [[EmployeeTypeDropdown]];
Do not forget to change all field names, <Your_ID> and used in the script.
To find <Your_ID>, open Console tab in the Developer Tool (press F12), insert following code and run:Code:
$(".ard-sublist-webpart").attr("ard-webpart-id");
To find , see example:
Please let me know if it is helpful.
0 -
Original Post by Sandy (Imported from Ardevia Forum)
Hi Liliia,
I tried this but when I went to find out <Your_ID> in the Console, I got the following error:
Object doesn't support property or method 'attr'.
Still, when I found the id, I could apply the calculated code and it worked perfectly.
I am now finding that I need to change label for a sub-list column based on the value in another of the sub-list columns. Is this possible?Also, how would I do this on the Display Form?
Thank You
Cheers
Sandy0 -
Original Post by Liliia (Imported from Ardevia Forum)
Hi Sandy,
You can change a label for a sub-list column based on the value in another of the sub-list columns in the same way.
Add Calculated expression for the sub list dropdown, that will be the source for calculationsCode:
var val = [[@SubListCurrentRow.TestSubList.BaseDropdown]] == 'test1' ? 'Label for test1':'Label for test2'; jQuery('.ard-sublist-webpart[ard-webpart-id="<Your_ID>"] .ms-listviewtable.ms-listviewgrid>tbody>tr.ms- viewheadertr>th:nth-child()').find('div[colid="coreContent"]:first').text(val); return [[@SubListCurrentRow.TestSubList.BaseDropdown]];
About the Display Form, it should work the same.
Feel free to contact us if you need more assistance.0 -
Original Post by Sandy (Imported from Ardevia Forum)
Hi Liliia,
When I try to apply a Calculated Expression on the Display Form, the Initial and Calculated areas are disabled for entry. Is there another way around this?
Cheers
Sandy0 -
Original Post by Andrii Katsiubka (Imported from Ardevia Forum)
Hi Sandy,
Workaround on Display form is to use Visible or Enabled expression.
But in this case your expressions should return value true0 -
Original Post by Sandy (Imported from Ardevia Forum)
Hi,
I have applied the calculated expression to the drop-down in my sub-list and it is not changing the label on the column next to it, rather, the drop-down column is continuously flickering.
Code is copied from above with the column, column number and webpart-id replaced.
Cheers
Sandy0 -
Original Post by Taras Lozynskyy (Imported from Ardevia Forum)
Hi Sandy.
This code was tested on our environment, and it works fine.
You can use our Support and we will try to fix your issue.0 -
Original Post by Sandy (Imported from Ardevia Forum)
Hi,
I have managed to get the variable label names working, but how can I change the font strength on these, they are currently not bold but I would like them to be, the same as the rest of the labels on the form.
thanks
Sandy0 -
Original Post by Vladislav (Imported from Ardevia Forum)
Hi,
You can try add standard Script Editor Web-part and try to set font strength using css selectors there.
0
Please sign in to leave a comment.
Comments
11 comments