Skip Navigation

[Resuelto] Display a wiew output in a single line field

This support ticket is created hace 3 años, 9 meses. There's a good chance that you are reading advice that it now obsolete.

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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: ,

Este tema contiene 7 respuestas, tiene 2 mensajes.

Última actualización por Rune Brynestad hace 3 años, 9 meses.

Asistido por: Minesh.

Autor
Mensajes
#1938425

I have created a view output that displays a score for a table view based on some conditions. This is done through a custom Javascript code. The correct output for this example is 96. I have tested that the output is 96 on this test page. All is good so far.
enlace oculto

The next step is to use the view shortcode in a single line field to display a dynamic output in another View. When I do, the output value is changed to 93.

Do you have any idea why the output value is changing?

Here is a screen recording so you can see what I'm trying to do.
enlace oculto

Thanks in advance

Kind regards
Rune

#1938951

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please send me problem URL of the listing page where you are trying to display the scorer as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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.

#1939005

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I see you added the view to single line field and added the that field to another view.

To calculate the correct value we have to determine each table with unique class/id.

To do that, I've adjust the table class within the following view as:
=> enlace oculto

<table width="100%" class="myscore[wpv-post-id]" style="display:none;">

Also, I've added the JS at top of the view's loop editor as:

<script>
  function calculate_score(postid){
    	var bran = jQuery(".js-wpv-view-layout table.myscore"+postid+" tr td.bran:contains(Ja)").length;
   
  jQuery('div.bran .count').html( bran );
  jQuery('div.bran .score').html( ( ( bran / jQuery(".js-wpv-view-layout table.myscore"+postid+" .bran").length ) * 100 ).toFixed(0) );
  }

</script>

I can see now on the page it shows 96.

Can you please confirm.

#1939041
dashboard.jpg

Yes, it works for the Akersgata 20 record. But I'm going to update the score field for every records in the Building post type the same way.

I have created a similar view for the building Bygdøy Allé 1
enlace oculto
The output score is calculated to 91 which is correct

When I update the building score for Bygdøy Allé 1 with the shortcode [wpv-view name="building-score-total-bygdoy-alle-1"]
enlace oculto
Both Akersgata 20 and Bygdøy Allé 1 displays the value 91 on the listing page
enlace oculto (Se screenshot)

#1939149

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

The thing is that you have complicated setup and I'm not sure why you are adding the hidden table when you do not want to display the table.

Another thing is that this is nothing to do with Toolset (views) as you have your custom calculations and you will require to adjust the said JS code you added to it.

However - I've adjusted the JS function as given under:

              <script>
  function calculate_score(postid){
    	var bran = jQuery(".js-wpv-view-layout table.myscore"+postid+" tr td.bran:contains(Ja)").length;
   
  console.log("bran=="+bran);
  console.log("bran111=="+jQuery(".js-wpv-view-layout table.myscore"+postid+" .bran").length);
  jQuery('div.bran .count').html( bran );
  jQuery('div.bran'+postid+' .score').html( ( ( bran / jQuery(".js-wpv-view-layout table.myscore"+postid+" .bran").length ) * 100 ).toFixed(0) );
  }

I can see now different values for both of the post score.

If you do not know how to adjust the JS code, I suggest you should consult pro JS expert on this and they will help you to fix this issue.

#1939259
dashboard2.jpg

Thanks again for looking into this.

One final question. When I create a new similar view for another building. Which part of this Javascript do I need to change for every new view?

<script>
function calculate_score(postid){
var bran = jQuery(".js-wpv-view-layout table.myscore"+postid+" tr td.bran:contains(Ja)").length;
console.log("bran=="+bran);
console.log("bran111=="+jQuery(".js-wpv-view-layout table.myscore"+postid+" .bran").length);
jQuery('div.bran .count').html( bran );
jQuery('div.bran'+postid+' .score').html( ( ( bran / jQuery(".js-wpv-view-layout table.myscore"+postid+" .bran").length ) * 100 ).toFixed(0) );
}
</script>

When I use this code on other Views without changing anything. The score is 0 for all but the first. I think we're pretty close to getting this to work now 🙂

enlace oculto

My 3 Views:
enlace oculto
enlace oculto
enlace oculto

Kind regards
Rune

#1939281

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I've changed the following line of the code to both of the view from:

<div class="bran"><span class="score"> 0 </span> </div>

To

<div class="bran[wpv-post-id]"><span class="score"> 0 </span> </div>

It should work now and thank you for understanding that this issue has nothing to do with Toolset but pure custom Javascript code. That is beyond the scope of our support policy.

#1939389

My issue is resolved now. Thank you!