Conditionally show/hide fields on Display Form

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
TonyDuke
Posts: 71
Joined: Mon Sep 11, 2017

21 Sep 2017

I'm having a bit of an issue with conditionally showing and hiding fields on a display form. The test is if Address Line 1 is blank then hide items with CSS addressFields, this works absolutely fine in the edit form using the .value() code, but I cannot get it to work in the display form using .value() or the code below? The function is called on form load.

Code: Select all

function showAddressFields () {
	var AddressLine1 = fd.field('Address_x0020_Line_x0020_1').control()._el().text();
	if (AddressLine1 == "") {
		$('.addressFields').hide();
	}
}
Address Line 1 is a single line of text field.

Help appreciated.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

21 Sep 2017

The actual value returned by the empty field is most likely different. In my tests, the value returned for empty fields was a space. Try to compare value to " " instead of "".
Cheers

User avatar
TonyDuke
Posts: 71
Joined: Mon Sep 11, 2017

21 Sep 2017

Hi Nikita,

I did previously try that as you are correct in the display form if I get the value using the console it return " " but this doesn't work either, I've tried it a couple of other ways too -

Code: Select all

if (AddressLine1 != "") {
		$('.addressFields').show();
And then setting the fields to hidden by default, they just stay hidden, I've also tried

Code: Select all

if (!AddressLine1) {
		$('.addressFields').show();
Again with the fields hidden by default.

None of the above works, have you any other ideas I could try?

Thanks

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

21 Sep 2017

Try this then:

Code: Select all

function showAddressFields() {
	var AddressLine1 = $.trim(fd.field('Address_x0020_Line_x0020_1').control()._el().text());
	if (AddressLine1 == "") {
		$('.addressFields').hide();
	}
}
Cheers

User avatar
TonyDuke
Posts: 71
Joined: Mon Sep 11, 2017

21 Sep 2017

Hi Nikita,

Yes, that's great thanks sorted the issue and the fields are now hidden if the address is empty.

Great stuff

Thanks

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests