Jump to content

Trying to conditionally hide blank fields in a details page


Recommended Posts

Hi 

I have a details page from a view and there's up to 45 fields they may need to enter (I know its a lot - but sometimes there might only be 5). The number depends on the complexity of the person's role. 
The logic requires checking the display only data, if missing, then hide the corresponding editable field in the second table. So if variable 6 in my reference table is blank, I don't want the user to see and add a value to the matching field in table 2. I am able to hide all the empty fields.

I've created a calculated value to confirm if the associated field is missing and passed this to a virtual field (v1) to read in js.

CASE
WHEN CAST([@field:variable] as NVARCHAR(max)) = '' THEN
'Missing'
ELSE
[@field:variable]
END

My JS is in my header and is:

<script>
var check_field=document.getElementByName("cbParamV1")[0].value;

if (check_field ='Missing') {
document.getElementById("tbl_tech8").style.display="none";}

else {
document.getElementById("tbl_tech8").style.display="none";}
</script>

What am I doing wrong? Any help would be appreciated. I've tried so many variations and combinations and just can't figure it out.

Link to comment
Share on other sites

Hi @Jodie

From what I can see here, there could be multiple reasons why this might not work:

1. In a one CASE WHEN statement you can only return one DataType. I believe [@field:variable] is a number/integer type of data, so after THEN you return a string and after else you return a number, which is forbidden.
Also, to check if a number cell is empty use IS NULL. Here is an SQL statement that should work:

CASE
WHEN [@field:variable] IS NULL THEN
'Missing'
ELSE
CAST([@field:variable] as NVARCHAR(max)) 
END


2. In document.getElementByName("cbParamV1")[0].value plural 's' is missing, so it should be getElementsByName. Also, the name of the first virtual field I believe should be cbParamVirtual1, so this code part will look like document.getElementByNames("cbParamVirtual1")[0].value

3. In "if/else" statement you put the same document.getElementById("tbl_tech8").style.display="none"; for if and else conditions.

4. IDs of table elements usually do not have "tbl_tech8" naming, it could be something  like "tbl_tech8_146f65b245c8c2" and changes dynamically on page load, so a different selector could be required.


But without seeing the actual details DataPage and its setup, it would be hard to tell for sure what to do to make it work. You could share a link to that DataPage for furhter checking.

Link to comment
Share on other sites

Thanks for the tips. I've tried the above but still not quite there either. I'm wondering if part of the issue is that I'm trying to hide radio buttons and in a details page. I'm not sure that I've pulled out the right ID for the field, but I don't think even virtual field is coming through. When I go to see how the code ran using F12, the virtual field is highlighted in red and not the blue like others. 

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...