What you posted - is the the entire code you are using on the form? Because you don't have anything that is triggering the code to actually run at any time.
Here's an example of some code that should work (I tested in Version 11.0.2311.50556 Classic Designer) and checking the box hide the row of the table.
//Document Ready is run when the page is loaded.
$(document).ready(function() {
//Any changes to the table with the myTable class runs the code.
$(".myTable").change(function() {
//Loop through all checkedcheckboxes with the ColorCheckbox class.
$(".ColorCheckbox input:checked").each(function(){
//If the value is * then hide the row, otherwise show it.
if ($(this).val() == "*"){
$(this).closest("tr").removeClass("hiderow");
} else {
$(this).closest("tr").addClass("hiderow");
}
});
});
});
A few things to be careful about here:
- Hidden rows in this manner are still going to be validated on form submission, so any required fields that are not populated, or fields with invalid values, will stop the form from being submitted, but the user won't be able to see why, because the row is hidden.
- Additionally, this code won't work on a read-only version of the form (including the Monitor page, and what is archived to the repository).
- This code is only triggered upon changes to the table, so it won't happen automatically at form load from changes made on a prior task - but there are ways we can rewrite it to achieve that.
It would be significantly better to use field rules to hide the fields in the row. Of course, the Field rules just hides the fields in the row, not the row itself. But if you make the field rules hide every field in the row, so that it's just a blank row, now it will follow built-in rules for handling the hidden fields, and we can just use some Javascript to do the cleanup to hide the row itself. (I tested in Version 11.0.2311.50556 Classic Designer)
//Document Ready is run when the page is loaded.
$(document).ready(function() {
//Run the code when the form is loaded.
HideRowFunction();
//Any changes to the table with the myTable class runs the code.
$(".myTable").change(HideRowFunction);
//Function to hide the rows. This looks at each row in the table,
//and if it has any children with the lf-container-hidden class
//(which is automatically applied by the field rules) then the
//entire row is hidden.
function HideRowFunction() {
//Loop through all rows in the table with the myTable class.
//Remove the hiderow class. Then loop through the rows that have
//the lf-container-hidden class on any field and reapply the
//hiderow class just to those rows.
$('.myTable tr').each(function(){
$(this).closest("tr").removeClass("hiderow");
});
$('.myTable .lf-container-hidden').each(function(){
$(this).closest("tr").addClass("hiderow");
});
}
});
P.S. You can use to {...} code button here in LFAnswers to make your code more readable.