Disable form field based on connected record value

I have a number of tasks, some tagged for individual volunteers, some for groups, and some for both.

My form to register has a radio button for individual/group and additional fields are shown when group is selected (group size, group name).

I am sure I can figure out how to disable the group option with javascript/jquery, but what is the syntax for pulling in a connected record value?

ie.

if connected value = individual

then disable "group" radio button

Again, I can figure out the operators, disable command, etc. But how do identify the connected value?

Code by Brad wasn't working for me either and I noted that a ";" was required after ""Complete")"


Code below is corrected to add ";"


$(document).on('knack-view-render.view_58', function(event, view, data) {

if ($(".field_84 .kn-value").text() == "Complete"); {

$("#view_67").css("visibility", "hidden");

$("#view_67").css("height", "0px");

}

});

Jørgen, you should be able to explore elements of your page with Firefox or chrome to discover how your fields and views are labelled, then replace those values in your code.

Hi Jørgen, there could be a number of things:

  • What's the field value you're checking for?
  • Are the view and field numbers for your app set correctly?

Hi Mark,

Should be possible, you can use jquery’s remove method or css to hide it, like with Brad’s code.

Nice of you guys to share that.

I’m looking for something much simpler. I want to disable a single field on an edit form. Any chance?

Thanks for sharing. This hides a view within a page depending on a field value, and totally borrows from your code.

$(document).on('knack-view-render.view_58', function(event, view, data) {
  if ($(".field_84 .kn-value").text() == "Complete") {
    $("#view_67").css("visibility", "hidden");
    $("#view_67").css("height", "0px");
  }
});

Hey Guys,

I have developed a work around for anyone interested. My Detail view is as follows:

Volunteer Opportunity >

Form: Add Application to Opportunity

The opportunity has a group/individual tag that I add to details view and hide, then use the following code to validate my form (Group/Individual application selector) against the connected value

$(document).on('knack-view-render.view_48', function (event, view, data) {
    $(document).on('knack-view-render.view_4', function () { //fires when both views loaded
        if ($(".field_17 .kn-value").text() == "Individual") { //string for connected tag (hidden)
            $("#kn-input-field_84 .kn-input-label").text("Individual only"); //change label on app
            $("#view_48 .kn-input input[value='Group']").attr("disabled", true); //disable Group radio button
            $("#view_48 .kn-input input[value='Group']").attr("checked", false); //
            $(".option").last().addClass("disabled"); //add unique class to disabled option
            $(".disabled").css('opacity', '.6'); //fade diabled option
        }
    });
});