Within a Details View, how do I hide a link based on the value in a field?

On a Detail View, I've created a link to another view. I want to hide that link when a field value above it is equal to ZERO. I can't use the conditional display rules on this link (because it's a link and not a field). Is there another way to do this with the builder, or would I need to resort to javascript? I've been trying the following javascript and it isn't working. I'm just learning javascript so it could be making a simple mistake:

$(document).on('knack-scene-render.scene_664',   function(page) {

if ($(’#view_1024 td.kn-value .field_317’).text() == "0.00") { (’#view_1024 .field_320’).hide()

Tanner, did you ever get this working? I'm trying to do the exact same thing. =)


I will take a look Brad. Thank you very much for taking the time to support me!

Hi Tanner,

That's right, it means your if statement is returning false every time.

Might be worth using the Knack.models to find the value without inspecting view controls - se Stevan's work here http://helpdesk.knackhq.com/support/discussions/topics/5000019533 and take not of how to set a view data variable, and then inspect a field's data.

That might work better here and should only add an extra line or two.


Thanks Brad... the alert window is appearing but the alert text is now blank, so maybe this means it's not finding the field. I get the same result on any page I go to. Not sure what to try next. I'm nearly certain I have the view#, and field # correct, but something must be wrong. And I've tried it with and without the 'td.kn-value'. I'm testing the alert code you provided and nothing else. Is that how you intended? Or should the alert code be part of a larger block of code?

Sorry Tanner, I missed the proper selector and .text() to the alert! This should display the field text:

alert($('#view_1024 td.kn-value .field_317').text());

And it will fire every time until you remove it. The alternative is to use Console.log instead which doesn't interrupt any user, and you inspect the output in a web console - Chrome browser easiest for this in my opinion.

See http://www.w3schools.com/js/js_output.asp for info on console.log.

Thanks for your support Brad! I tried your samples above (and a few variations) with no luck. If I try to go to as simple as a test as possible, such as your "alert" test, what should that do exactly? When I try that code on it's own, it will always show an alert when I load any page of that app. The alert literally shows:

#view_1024 td.kn-value .field_317

And that's all. If it finds that field, should it print it's value?

Thanks again for your help!

Without spotting an obvious issue with your code (a JS expert might here), try inspecting the values to make sure you're code is right.

I'd try inserting an alert before your if statement to check the value of field_317 first:

alert('#view_1024 td.kn-value .field_317');

Although it shouldn't matter functionally, you could target the view render event of view_1024 instead of the whole scene, and your code could be simplified. And sometimes I've found some padding spaces around values so using the Trim function removes them for accurate checking. Combined the code then might be:

$(document).on('knack-view-render.view_1024', function (event, view) {
  if($('.field_317').text().trim() == "$0.00") ) {