diff --git a/actions.php b/actions.php
index 52ab22ac..44004a7b 100644
--- a/actions.php
+++ b/actions.php
@@ -106,23 +106,7 @@ function sp_save_post( $post_id ) {
delete_post_meta( $post_id, 'sp_result');
$stats = (array)sp_array_value( $_POST, 'sp_stats', array() );
foreach ( $stats as $table ) {
-
- // Add values from each row where total is blank
- $total = sp_array_value( sp_array_value( $table, 0, null ), 0, null );
- if ( $total == null ):
- $values = array();
- foreach ( $table as $row ):
- $value = sp_array_value( $row, 0, null );
- if ( is_numeric( $value ) ):
- $values[] = $value;
- endif;
- endforeach;
- if ( sizeof( $values ) ):
- $total = array_sum( $values );
- endif;
- endif;
-
- // Save first column of total row as result
+ $total = sp_array_value( sp_array_value( $table, 0, null ), 0, null );
add_post_meta( $post_id, 'sp_result', $total );
}
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
diff --git a/helpers.php b/helpers.php
index 6d1c062b..9c3ef47f 100644
--- a/helpers.php
+++ b/helpers.php
@@ -384,14 +384,14 @@ if ( !function_exists( 'sp_stats_table' ) ) {
$i++;
endforeach;
if ( $total ):
- $values = array_key_exists( 0, $stats ) ? $stats[0] : array();
+ $values = sp_array_value( $stats, 0, array() );
?>
|
- |
+ |
diff --git a/sportspress-admin.js b/sportspress-admin.js
index 16c8100d..37578519 100644
--- a/sportspress-admin.js
+++ b/sportspress-admin.js
@@ -34,28 +34,23 @@ jQuery(document).ready(function($){
});
// Total stats calculator
- $('.sp-stats-table').on('updateTotals', function() {
- $self = $(this);
- $self.find('.sp-total input').each(function(i) {
- var sum = 0;
- $self.find('.sp-post').each(function() {
- $el = $($(this).find('input')[i]);
- if($el.val() != '') {
- if($.isNumeric($el.val())) sum += parseInt($el.val(), 10);
- } else {
- sum += parseInt($el.attr('placeholder'), 10);
- }
- });
- $(this).attr('placeholder', sum);
+ $('.sp-stats-table .sp-total input').on('updateTotal', function() {
+ index = $(this).parent().index();
+ var sum = 0;
+ $(this).closest('.sp-stats-table').find('.sp-post').each(function() {
+ val = $(this).find('td').eq(index).find('input').val();
+ if($.isNumeric(val)) {
+ sum += parseInt(val, 10);
+ }
});
+ $(this).val(sum);
});
// Activate total stats calculator
- $('.sp-stats-table .sp-post input').on('keyup', function() {
- $(this).closest('.sp-stats-table').trigger('updateTotals');
- });
-
- // Trigger total stats calculator
- $('.sp-stats-table').trigger('updateTotals');
+ if($('.sp-stats-table .sp-total').size()) {
+ $('.sp-stats-table .sp-post td input').on('keyup', function() {
+ $(this).closest('.sp-stats-table').find('.sp-total td').eq($(this).parent().index()).find('input').trigger('updateTotal');
+ });
+ }
});
\ No newline at end of file
diff --git a/team.php b/team.php
index 90079af6..4a17f64f 100644
--- a/team.php
+++ b/team.php
@@ -63,7 +63,7 @@ function sp_team_stats_meta( $post ) {
$placeholders[ $league_id ] = sp_get_stats_row( $args );
endforeach;
- sp_stats_table( $data, $placeholders, 0, array( 'League', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), true, 'sp_league' );
+ sp_stats_table( $data, $placeholders, 0, array( 'League', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), false, 'sp_league' );
sp_nonce();
}
?>
\ No newline at end of file