PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.23
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.23
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
wp-data-access / WPDataAccess / Simple_Form / WPDA_Simple_Form_Item_Boolean.php

WPDA_Simple_Form_Item_Boolean.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.23, at WPDataAccess/Simple_Form/WPDA_Simple_Form_Item_Boolean.php

75 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
5 *
6 * @package WPDataAccess\Simple_Form
7 */
8
9 namespace WPDataAccess\Simple_Form {
10
11 class WPDA_Simple_Form_Item_Boolean extends WPDA_Simple_Form_Item {
12
13 protected $checkbox_on = '1';
14 protected $checkbox_label = '';
15
16 /**
17 * WPDA_Simple_Form_Item_Boolean constructor.
18 *
19 * @param array $args
20 */
21 public function __construct( $args = array() ) {
22 parent::__construct( $args );
23
24 $this->checkbox_label = $this->get_item_label();
25 $this->set_label( '' );
26 $this->set_item_hide_icon( true );
27
28 if ( isset( $args->checkbox_value_on ) ) {
29 $this->checkbox_on = $args->checkbox_value_on;
30 }
31 }
32
33 /**
34 * Overwrite method
35 */
36 protected function show_item() {
37 if ( 'new' === $this->show_context_action ) {
38 $checked = $this->checkbox_on === $this->item_default_value ? 'checked' : '';
39 $this->item_value = $this->checkbox_on === $this->item_default_value ? $this->checkbox_on : '';
40 } else {
41 $checked = $this->checkbox_on === $this->item_value ? 'checked' : '';
42 }
43 ?>
44 <label>
45 <input type="checkbox"
46 id="<?php echo esc_attr( $this->item_name ); ?>_chk"
47 value="<?php echo esc_attr( $this->checkbox_on ); ?>"
48 class="wpda_data_type_checkbox"
49 <?php echo $this->is_readonly ? ' disabled="disabled"' : ''; ?>
50 <?php echo esc_attr( $checked ); ?>
51 />
52
53 <input type="hidden"
54 id="<?php echo esc_attr( $this->item_name ); ?>"
55 name="<?php echo esc_attr( $this->item_name ); ?>"
56 value="<?php echo esc_attr( $this->item_value ); ?>"
57 />
58 <?php echo esc_attr( $this->checkbox_label ); ?>
59 </label>
60 <script type="text/javascript">
61 jQuery('#<?php echo esc_attr( $this->item_name ); ?>_chk').on('click', function() {
62 if (jQuery('#<?php echo esc_attr( $this->item_name ); ?>_chk').is(':checked')) {
63 jQuery('#<?php echo esc_attr( $this->item_name ); ?>').val('<?php echo esc_attr( $this->checkbox_on ); ?>');
64 } else {
65 jQuery('#<?php echo esc_attr( $this->item_name ); ?>').val('0');
66 }
67 });
68 </script>
69 <?php
70 }
71
72 }
73
74 }
75