cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sbonera
Advocate II
Advocate II

Javascript to check all cells are yes in a table and remove class from button

Hi

 

Any help, guidance, is this right place for javascript questions for portal, i hope so.

 

I have an entity list and one column has a yes/no response .  I am trying to get it so that once all rows are completed and the answered column is all yes's then remove a class from a button so it can be clicked.

 

entitylist.PNG

 

I have this code already that colours the rows green when they are yes , but if i replace $(this).parent().addClass('success'); with $('mybtn).removeClass('disabled');  it would make the button active when any are yes

 

$(document).ready(function (){
$(".entitylist.entity-grid").on("loaded", function () {
$(this).children(".view-grid").find("td[data-attribute='py3_yescheck']").each(function (){
// do something with each row
if ($(this).text() == 'Yes') {
$(this).parent().addClass('success');
}
});
});
});
 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
justinburch
Microsoft
Microsoft

Hi @sbonera,

You need to identify the output of all iterations in the each statement. Consider the following:

$(document).ready(function (){
    $(".entitylist.entity-grid").on("loaded", function () {
        var isSuccess = true;
        $(this).children(".view-grid").find("td[data-attribute='py3_yescheck']").each(function (){
            if ($(this).text() == 'No') {
                isSuccess = false;
            }
        });
        if (isSuccess) {
            $('mybtn).removeClass('disabled');
        }
    });
});

Please note that there are fundamental flaws to this approach: if your grid becomes paginated (there is more than one page), this will only look at the visible page. This means that if you have sorting enabled, they can intentionally sort to hide the "No" responses" and enable the button.

View solution in original post

1 REPLY 1
justinburch
Microsoft
Microsoft

Hi @sbonera,

You need to identify the output of all iterations in the each statement. Consider the following:

$(document).ready(function (){
    $(".entitylist.entity-grid").on("loaded", function () {
        var isSuccess = true;
        $(this).children(".view-grid").find("td[data-attribute='py3_yescheck']").each(function (){
            if ($(this).text() == 'No') {
                isSuccess = false;
            }
        });
        if (isSuccess) {
            $('mybtn).removeClass('disabled');
        }
    });
});

Please note that there are fundamental flaws to this approach: if your grid becomes paginated (there is more than one page), this will only look at the visible page. This means that if you have sorting enabled, they can intentionally sort to hide the "No" responses" and enable the button.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (3,925)