Conditionally show/hide fields on Display Form
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.
Address Line 1 is a single line of text field.
Help appreciated.
Code: Select all
function showAddressFields () {
var AddressLine1 = fd.field('Address_x0020_Line_x0020_1').control()._el().text();
if (AddressLine1 == "") {
$('.addressFields').hide();
}
}
Help appreciated.
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 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
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 -
And then setting the fields to hidden by default, they just stay hidden, I've also tried
Again with the fields hidden by default.
None of the above works, have you any other ideas I could try?
Thanks
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();
Code: Select all
if (!AddressLine1) {
$('.addressFields').show();
None of the above works, have you any other ideas I could try?
Thanks
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 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
-
- Information
-
Who is online
Users browsing this forum: No registered users and 7 guests