| 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 |
|