Dropdown list with number to select goals
-
Hello again Antoine,I would like the player to be able to display a list with a number to indicate the goals, so that the player does not have to type it and is more comfortable.
I show you a picture:
How could I do it?
Thank you very much for your help.
-
Best option would be to rewrite the prediction form template. There is an example in the extensions post on the forum how to change the template.
Other option is a small piece of javascript that changes the inputs to dropdowns.
I′ve rewrited the prediction form template with the example that I hace found in the extensions and I have included the code dropdown:
<select> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> </select>
But in not working…, look:
The code complete is this one:
/** * Plugin Name: Football Pool Extra Save Buttons * Description: Add save button after every match (if match prediction is still allowed). * Version: 3.0 * Author: Antoine Hurkmans * Author URI: mailto:[email protected] * License: MIT */ // Save this plugin in the "/wp-content/plugins" folder and activate it // class FootballPoolExtensionSaveButton { public static function init_extension() { add_filter( 'footballpool_predictionform_match_template', array( __CLASS__, 'match_row_template' ), null, 2 ); add_filter( 'footballpool_predictionform_match_template_params', array( __CLASS__, 'change_params' ), null, 4 ); } public static function change_params( $match_template_params, $match_id, $user_id, $is_user_page ) { if ( $match_template_params['match_is_editable'] == true ) { $match_template_params['save_button'] = '<input type="submit" value="save" />'; } else { $match_template_params['save_button'] = ''; } return $match_template_params; } public static function match_row_template( $match_template, $is_user_page ) { if ( ! $is_user_page ) { if ( strpos( $match_template, '<tr>' ) !== false ) { $match_template = '<tr id="match-%match_id%-%form_id%" class="%css_class%" title="' . __('match', 'football-pool') . ' %match_id%"> <td class="time">%match_time%</td> <td class="home">%home_team%</td> <td class="flag">%home_team_flag%</td> <td class="score">%home_input%</td> <td>-</td> <td class="score">%away_input%</td> <td class="flag">%away_team_flag%</td> <td class="away">%away_team%</td> <td>%joker%</td> <td title="' . __('score', 'football-pool') . '" class="numeric">%user_score%</td> <td>%stats_link% %save_button%</td> </tr>'; } else { $match_template = '<div id="match-%match_id%-%form_id%" class="%css_class% match-card match-type-%match_type_id%" title="' . __( 'match', 'football-pool' ) . ' %match_id%"> <div class="match-card-header"> <span class="matchdate">%match_datetime_formatted%</span> <span class="time">%match_time%</span> </div> <div class="flag">%home_team_flag%</div> <div class="flag">%away_team_flag%</div> <div class="home">%home_team%</div> <div class="away">%away_team%</div> <div class="score"> %home_input% <select> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> </select> <div class="actual-score">%home_actual_score%</div> </div> <div class="score"> %away_input% <div class="actual-score">%away_actual_score%</div> </div> <div class="match-card-footer"> <div class="user-score">%user_score_txt%</div> <div class="fp-icon">%stats_link%</div> <div class="fp-icon">%joker%</div> </div> <div class="match-card-save">%save_button%</div> </div>'; } } return $match_template; } } add_filter( 'plugins_loaded', array( 'FootballPoolExtensionSaveButton', 'init_extension' ) );
I know I’m doing something wrong, could you help me where I have to put the correct code, please?
Thanks
-
This reply was modified 2 years ago by
joseba912.
It is not just a matter of adding the code. If you want to replace the text inputs with a select, you will have to replace the
%home_input%
and%away_input%
parameters with the select tags.But that will only show the select and you also want to show the value that the user gave on a previous save. Which means that you will need to add some dynamic code into it. Which makes me reconsider my first answer: I think it is better to not change the template, but only to change the beforementioned parameters via the filter
footballpool_predictionform_match_template_params
.I wanted to quickly type a short example for you, but then I found some code that I created some time ago that does exactly what you want ??
One small note though, these dropdowns will not work together with the asynchronous saves, so users will have to remember to click the save button.Thank you very much for your help and quick response.
We can close another topic! ??
-
This reply was modified 2 years ago by
- The topic ‘Dropdown list with number to select goals’ is closed to new replies.