From 2be943f45a70cc0d5e80da2d0d11cee2f13b3f6d Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 3 Mar 2017 08:44:42 -0800 Subject: [PATCH] Switch fix --- e107_handlers/form_handler.php | 13 ++++++++----- e107_web/js/bootstrap.switch.init.js | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 2c9d994ca..032b74fc1 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -2251,7 +2251,7 @@ class e_form if(empty($options['id'])) { - $options['id'] = ''; + unset($options['id']); } // $options['class'] = 'inline'; $text = ""; @@ -2341,7 +2341,7 @@ class e_form if(!empty($options['switch'])) { - return $this->switch($name,$checked_enabled, array('on'=>$options_on['label'],'off'=>$options_off['label']),$options); + return $this->flipswitch($name,$checked_enabled, array('on'=>$options_on['label'],'off'=>$options_off['label']),$options); } elseif(!empty($options['inverse'])) // Same as 'writeParms'=>'reverse=1&enabled=LAN_DISABLED&disabled=LAN_ENABLED' { @@ -2368,7 +2368,7 @@ class e_form * @param array $options * @return string */ - public function switch($name, $checked_enabled = false, $labels=array('on' =>LAN_ON, 'off' =>LAN_OFF), $options = array()) + public function flipswitch($name, $checked_enabled = false, $labels=array('on' =>LAN_ON, 'off' =>LAN_OFF), $options = array()) { if(!empty($options['inverse'])) @@ -2385,9 +2385,11 @@ class e_form } + $switchName = $name.'__switch'; + $js_options = array( // Each form element has its own options. - $name => array( + $switchName => array( 'size' => $options['switch'], 'onText' => $labels['on'], 'offText' => $labels['off'], @@ -2406,7 +2408,7 @@ class e_form e107::js('footer', '{e_WEB}js/bootstrap.switch.init.js', 'jquery', 5); $text = $this->hidden($name, (int) $checked_enabled); - $text .= $this->checkbox($name, $checked_enabled, $checked_enabled); + $text .= $this->checkbox($switchName, (int) $checked_enabled, $checked_enabled); return $text; } @@ -2862,6 +2864,7 @@ class e_form function hidden($name, $value, $options = array()) { $options = $this->format_options('hidden', $name, $options); + return "get_attributes($options, $name, $value)." />"; } diff --git a/e107_web/js/bootstrap.switch.init.js b/e107_web/js/bootstrap.switch.init.js index 9fdbf9150..00b4f45d8 100644 --- a/e107_web/js/bootstrap.switch.init.js +++ b/e107_web/js/bootstrap.switch.init.js @@ -3,6 +3,9 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}}; (function ($) { + + + /** * @type {{attach: e107.behaviors.bootstrapSwitchInit.attach}} */ @@ -24,13 +27,19 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}}; size: options.size || 'mini', onText: options.onText || null, offText: options.offText || null, - wrapperClass: options.wrapperClass || null - // state: + wrapperClass: options.wrapperClass || null, + // disabled: false + // state: $('input[type="hidden"][name="' + name + '"]').data('on') // inverse: options.inverse // this is 'reverse' - default values but reversed order. }); + + $(this).on('switchChange.bootstrapSwitch', function (event, state) { - var name = $(this).attr('name'); + + var tmp = $(this).attr('name').split('__'); + + var name = tmp[0]; // $(this).attr('name'); var checked = true; if(state === false) @@ -47,7 +56,7 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}}; $('input[type="hidden"][name="' + name + '"]').val(value); - event.preventDefault(); + // event.preventDefault(); }); } });