Hide Component based on field value

Hello TB Community-

Just a simple Javascript snippet to hide a component or element based on a field value:

Hide Component Example:

TB.render('component_3', function(data) {    
    var fieldValue = data.record.field_385;
    
    if (fieldValue === "Closed") {
        TB.hideComponent('component_13');
    }
});

Hide Element Example:

TB.render('component_3', function(data) {    
    var fieldValue = data.record.field_385;

        var elementToHide = document.getElementById('x_element_page_81_4');
        if (elementToHide) {
            elementToHide.classList.add('hide');
    }
});

Just change the element or component number accordingly. The component in the “TB.render” section should be the component that the field is in that you want to base the hide/show.

3 Likes

Nice - you can also avoid the addClass with the built-in JQuary function .hide() / .show()
and document.getelem can be changed to $(“#x_element_page_81_4”)