Skip Navigation

[Resolved] Assistance with updating some custom javascript code you provided in the past.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 22 replies, has 3 voices.

Last updated by Minesh 1 year, 1 month ago.

Assisted by: Minesh.

Author
Posts
#2642415

Can you assist with updating some custom javascript code you previously provided for us? The specific need is on our Standings by Session page here:

hidden link

Luo Yang previously assisted us with creating the page. Here is the support ticket where this page was achieved:

https://toolset.com/forums/topic/can-fields-within-a-custom-field-group-get-associated-with-each-other/

This page is now showing a white screen. I'm not 100% certain of the cause of the white screen here. That is a new development. But I know with 100% certainty one thing that we need assistance with on here that may be causing the white screen.

This page is created using two different views. The first one is here:

Teams List with Total Points and Results
hidden link

This is a view that I built to show Luo Yang all the data that we were trying to include. That view is on the page for a javascript he set up to pull data from, but it does not display on the page because I wrapped it in a div tag styled to display: none. . That was my understanding of the setup here, but now that I'm looking at the code on the page, I'm not seeing that display: none styling any more. I'm not sure what happened there. I don't recall removing it. I just tried to add it back and saving the page produced a fatal critical error for reasons unknown. That makes no sense to me why that is happening, but I'm reasonably sure the critical error is happening for the same reason the white screen is happening on the page.

Then the second view that Luo Yang set up is here:

Teams posts by session:
hidden link

The issue that we want to ask for assistance on is the calculation and display of total Wins and Losses. Previously, we had two radio fields for Match Result with two options (Win or Loss). One was for Team 1 Match Result and the other was for Team 2 Match Result. I had set it up that way thinking that was how the client wanted the Wins and Losses calculated and shown. But with our most recent tournament, the client had me change this. The way it was before, I determined the Winner and Loser by looking at how many games in the match were one and using the point spreads in each game as a tiebreaker in case both teams won the same amount of games. But now the client had me change this to where we want to have different fields set up for Game Result. So each game within a match will now have these two radio fields. If there are 4 games in the match, we'll have 4 different Team 1 Game Result fields and 4 different Team 2 Game Result fields. So we'll need to display 4 different result fields for each team within each match and then calculate the total wins and losses on the final standings page.

So in the first view that I set up, I know I have to change the table column previously showing the single result to instead show 4 columns to show all results. The code in the first view currently has

<td class="result-[wpv-post-id item='@team-1-match.parent'] [types field="team-1-result"][/types]">[types field="team-1-result"][/types]</td>

I'm now changing that to this instead:

<td class="result-[wpv-post-id item='@team-1-match.parent'] [types field="team-1-result"][/types]">[types field='team-1-result-mens-doubles'][/types] - [types field='team-1-result-womens-doubles'][/types] - [types field='team-1-result-mixed-doubles-a'][/types] - [types field='team-1-result-mixed-doubles-b'][/types]</td>

Note that I wasn't sure what to do with the [types field="team-1-result"][/types] piece that was within the class setting for the td on this. That is something Luo Yang added to the view I set up that I think was needed to work with what he set up on the second view.

I've now changed the td for the Team 2 results as well, leaving that same class bit as is. I know that class bit will need to be modified as well in both spots, but I'll wait to see what you say about that.

Note also that we have the output on this page set to group the standings by session. But the sessions used here were the ones we used on our first tournament. So I already know that output is going to have to be changed to reflect a different session structure on the second tournament. I think I should be able to do that myself by setting up a bunch of conditionals. But I can't try doing that until we get the white screen issue solved.

I'm thinking the white screen issue may be happening because the code Luo Yang set up is looking for fields that no longer exist in the Match field group. I removed the single Result fields for the full match and now have the Result fields set up for each game within the match.

#2642687

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

First of all, to know from where and what code line is caused the white screen.

Can you please enable the debug mode and then refresh the page and check what error you get:
- https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/#php-debugging

Or

You can send me admin access details with FTP.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2643003

Note that the calculations functionality is working fine on the Results page here:

hidden link

The calculation code on that page is

 [wpv-calculate][types field="team-1-score-mens-doubles"][/types]+[types field="team-1-score-womens-doubles"][/types]+[types field="team-1-score-mixed-doubles-1"][/types]+[types field="team-1-score-mixed-doubles-2"][/types] [/wpv-calculate]

and

[wpv-calculate][types field="team-2-score-mens-doubles"][/types]+[types field="team-2-score-womens-doubles"][/types]+[types field="team-2-score-mixed-doubles-1"][/types]+[types field="team-2-score-mixed-doubles-2"][/types] [/wpv-calculate]

So other than the <td class="score-[wpv-post-id item='@team-1-match.parent']"> bit and the team 2 one as well on the Standings page, it looks like I'm using it the same way in both views. So I'm not sure why it is no longer working on the Standings page. It didn't give this error before. I'm sure something has been changed that broke it, but I'm not sure what that would be.

#2643037

Actually, thinking through this more and I think I know why this one is broken. On the Results page, I set up a conditional display of the Points column where the calculation field has its output. That conditional does a check to make sure the Men's Doubles score field is greater than zero. That's because there are some matches that have no entry in that field. I had to set it up that way for a playoff system that the client requested.

So the Standings view is not accounting for that possibility where I'm using the calculation function and that is what is causing the white screen error when it hits a match that has no results in the fields it is using for the calculation. So I have to set up a similar conditional here.

OK, I've added that and now the white screen issue is resolved. Woo-hoo! I'm glad I was able to figure that one out on my own.

Now we can proceed with changing the javascript Luo Yang set up to instead use the 4 different Result fields for each team in each Match instead of the single Result field for each team that was present before.

#2643075

Now that I can see the Standings page with no white screen error, I can see there are going to be other questions I am going to have for getting this javascript to work as needed. If you filter the Standings on the Atlanta tournament by going here:

hidden link

The first other thing I see that is wrong is I have to figure out how to get the groupings by session setup you did for us to only display when the view has results. It should not display when the view results are "No items found". But that is set up on the page as follows, for example:

<h3>Morning - 3.0</h3>
[wpv-view name="teams-posts-by-session" session="Morning - 3.0"]

That's not something with the Javascript there, so let me know if you'd prefer for me to ask this question in a separate ticket. I'm not sure how I'd make that output conditional since it isn't in the View.

The second other thing I see that is wrong is the Total Points field is showing "NaN" on all the teams that made the playoff rounds in that tournament. I'm sure that's a problem with the calculation there as well. The playoff matches included ones that did not have games for Men's Doubles, Women's Doubles, Mixed Doubles A, and Mixed Doubles B, which is what the calculation field is based on. Those playoff matches only used the TeamMaker points system and those do not get added to the Total Points calculation. The TeamMaker results are treated kind of like penalty kick shootout goals in soccer. They don't get added to the Total Points. So the calculation is getting thrown off by the presence of matches that do not include those fields. I'm not sure if that is within how the Javascript is handling the numbers, or if it is within the calculation function code.

This is all stuff I've had to do to account for structural changes to these tournaments. I'm trying to make this system flexible enough to handle all the possibilities, but I'm finding that the client is making way more structural changes each time out than I was expecting. That's making it *very hard* to account for everything in here. I'm having to use tons of conditionals. But it's definitely improving with every tournament.

They are having another tournament in 4 days and I think the system changes made since the Atlanta tournament concluded will work considerably better for them this time out. I told them it is unlikely that we'll have the Standings page working fully by then, but I think everything else is looking good. We might be able to get parts of the Standings page done in time though. They understand that we're all learning with every tournament and gradually improving the system. They know it's going to take a few times before it is perfected. I think we have the Teams, Schedule, and Results pages working perfectly, while the Standings page is still a work in progress. We had the Standings page working perfectly on the first tournament, but the parameters have changed now, so it needs a bit more work now. This will have it working across multiple tournaments this time.

I may have another organization that will want this same pickleball league system coming onboard as a new client soon. I'm in negotiation with them now and they were referred to me by this client. That was the plan to get this to a point where I can just clone it and set it up quickly for new organizations without having to ask for additional help here. I think we're there with the functionality on the Teams, Schedule and Results pages now, unless the client hits me with more unanticipated structural changes. This ticket and maybe one more will hopefully get the Standings page to the same point.

Thanks as always for all assistance.

#2643097

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - please. You can open a new ticket with every new question you may have. This will help other users searching on the forum as well as help us to write correct problem resolution summery.

You shared too much information in single ticket and that raises the confusion about original question reported with the current ticket. Does original issue is resolved with this ticket?

#2643149

Will do on setting up new tickets for the other questions.

The original issue is sitll needed here. That issue is adjusting the javascript to tally the wins and losses from 4 results fields per team instead of 1 result field per team.

#2643157

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

On this page: hidden link

I can see the output is printed using the following view that displays the Team, Total Points, Wins, Losses columns.
=> hidden link

Where I can see the JS used and what is the formula to calculate the wins and losses?

or you want to do calculation on any other page? Can you please share all those details and let me review first.

#2643217

The javascript Luo Yang set up is on the actual edit screen for that Standings by Session page here:

hidden link

This calculation of wins and losses is not needed on any other page at this time. Note that it will only work on the Atlanta tournament results right now. I haven't gone back to the older matches and changed the values of the new fields yet. I plan to do full cleanup on all the older matches and get the Standings section working right for all tournaments during this process, but I'll wait to see everything working as it needs to with the Atlanta results before going backwards to make everything fit in this new approach.

To get the terminology right here though, I'm not sure if we should call the wins and losses a calculation. That might be better called a tally. To my knowledge, that tally does not use the custom code for calculations. It is done through the javascript as far as I know. It might be better/less confusing to only call things done with the calculation code calculations. We do have a calculation done on this page for the Total Points for each Match and then I think the Javascript takes those and adds them together to arrive at the Total Points total displayed in that column on the page.

Note that I already changed the view here:

hidden link

Previously, the code was done like this:

<td class="result-[wpv-post-id item='@team-1-match.parent'] [types field="team-1-result"][/types]">[types field="team-1-result"][/types]</td>

Now I have it like this, but I know this isn't correct:

<td class="result-[wpv-post-id item='@team-1-match.parent'] [types field="team-1-result"][/types]">[types field='team-1-result-mens-doubles'][/types] - [types field='team-1-result-womens-doubles'][/types] - [types field='team-1-result-mixed-doubles-a'][/types] - [types field='team-1-result-mixed-doubles-b'][/types]</td>

I just did it that way to give it as much of a start as I could so you'd know the four new fields that replaced the single field. Each game within a match has a corresponding result now, whereas before the result applied to the full match. I know with 100% certainty that the instance of [types field="team-1-result"][/types] in the class="" code has to be replaced, but I'm not sure how to do that, so I left it as it was for now. The javascript uses that in some way with generating the output from the other view.

#2644013

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked the following view you shared:
- hidden link

I see there is a td tag available with the class="result-[wpv-post-id item='@team-1-match.parent'] [types field="team-1-result"][/types]" but when I check on the frontend I do not able to find that td on frontend.

Where is that column get displayed with what?

With the following page:
hidden link

I can see it displays Team, Total points, Wins and Losses column where I can see the column that displays the result you are talking about?

Also, I do not see any JS code in the view that interfere with the result column or related to that result column you are talking about.

#2644119

In this view:

hidden link

The 6 td's are to display the following columns with the loop pulling from each match:

Team 1 name
Team 1 total score (calculation field)
Team 1 results (this is the part that needs to be changed to give results from four results fields instead of one)
Team 2 name
Team 2 total score (calculation field)
Team 2 results (this is the part that needs to be changed to give results from four results fields instead of one)

The way the classes of each td are defined is something Luo Yang set up that helps the javascript achieve its goal. The setup of classes here is something beyond my skill/knowledge level to change as needed here. I'm assuming that the specific one that says:

<td class="result-[wpv-post-id item='@team-1-match.parent'] [types field="team-1-result"][/types]">

Needs to be changed in some way. We're changing how the results works to use 4 fields instead of 1.

Then the JS that Luo Yang provided is here:

hidden link

<script src="
<em><u>hidden link</u></em>
"></script>
<link href="
<em><u>hidden link</u></em>
" rel="stylesheet"> 

<script>

jQuery( document ).ready(function($) {
    $('.total-score').each(function( index ) {
      var teamID = $(this).attr('team-id');
      var totalScore = 0;   
      $( ".score-" + teamID ).each( function(){
       if($(this).text() != '') { 
           totalScore += parseFloat($(this).text());
       }
      });
      $(this).text(totalScore);
    });

    $('.total-win').each(function( index ) {
      var teamID = $(this).attr('team-id');
      var totalWin = $( ".Win.result-" + teamID ).length;
      $(this).text(totalWin);
    });
   
    $('.total-loss').each(function( index ) {
      var teamID = $(this).attr('team-id');
      var totalLoss = $( ".Loss.result-" + teamID ).length;
      $(this).text(totalLoss);
    });
     
    //tablesorter
    $(function() {
      $(".tablesorter").tablesorter({ sortList: [[1,1], [2,1]] });
    });
});

</script>

That javascript takes the data from the first view above and formats how it displays in the second view here:

hidden link

The javascript is what takes all the data from the matches and provides the totals for points for all matches AND provides the wins and losses tally for both teams.

Then you helped us with setting up the display of the second view to group everything by session. The setup of that is below the javascript on the hidden link page.

#2645015

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Currently I can see its displaying the four columns on the frontend (Team, Total Points, Wins, Losses):
=> hidden link

Do you want to change the four column to six columns now? That is you want to display the following six columns instead of four that is currently being displayed. - is that correct?

The six columns now:

- Team 1 name
- Team 1 total score (calculation field)
- Team 1 results (this is the part that needs to be changed to give results from four results fields instead of one)
- Team 2 name
- Team 2 total score (calculation field)
- Team 2 results (this is the part that needs to be changed to give results from four results fields instead of one)

Its bit confusing now where you want to display six columns?

We can discuss about the javascript later on but first I would like to know on what page you want to display what columns?

The view you are talking about is currently displaying the dropdown select box to select "Tournaments ":
=> hidden link

The result of the view is you hide in the output editor - as you can see the view's result you have wrapped with div and you set it to display none:

<div style="display:none;">
[wpv-layout-meta-html]
</div>
#2645195

No, it should only display the same four columns. The wins and losses tallies should come from when the team is team one AND team two. That's what I believe the javascript does.

Yes, this view is hidden in the output editor. The way this all works is this view provides the data that the javascript then uses to put it in the format we're trying to achieve. When this view is not set to display: none, it shows on the page ABOVE the view that the Javascript manipulates. This view isn't in the format we need. That's why we hid it. This just provides the data to the Javascript. If the output is merely hidden from display, but still executing, the Javascript is still able to use the data from it. Understood that this is very confusing, but it worked, so I just hailed Luo Yang's skill level with making it happen like I frequently do with you.

The only change here is the Wins and Losses tallies need to come from the four fields instead of one field for each team. So it needs to check how many instances of Win and Loss appear across four different fields and keep a tally of that instead of just tallying one field. And actually, now the client has said to go ahead with counting the TeamMaker results as well. So I need to add those now. So it will be 5 fields, not 4. That is a change decided a few days ago in advance of their tournament this past Saturday. I'm guessing that won't impact the difficulty level of this ticket. I'm guessing the difficulty change comes with changing it from tallying 1 field to any number of multiple fields, not changing it from 4 to 5.

Unfortunately, that tournament got rained out, so I'm unable to use the results of that tournament to further perfect this system. Each tournament completed is getting everything that much closer to perfect. This change in how Wins and Losses tallies are generated is the last thing needed for having everything from that previous Atlanta tournament working as needed on this Standings by Session page. I was hoping to get the results from Saturday's tournament in here too as that would have helped confirm all is well with all the flexibility we've built into this to handle the variety of different match structures the client has wanted. They conduct the tournaments and I just try to play catch up with getting all of this displaying as we need it. Ultimately this will be a system that fully works in real-time as they conduct the tournaments, but right now it's still a work in progress. We have everything with Schedule, Results, and Teams working in real-time, but we're not quite there with Standings. Standings as Luo Yang set it up on this page and as you helped set up on the Standings by Round pages are proving to be considerably more difficult to achieve.

#2645337

Thank you for sharing these details.

Just wanted to let you know that Minesh is on holiday today.

He'll be back tomorrow and will be able to follow up on this ticket, accordingly.

Thank you for your patience.

#2646425

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please confirm the "Win" tally count on the following page, if that's correct I will try to implement the logic for the Loss column as well:
=> hidden link