1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 21:57:51 +02:00

Fix for unchecked-checkbox value submission.

This commit is contained in:
Lóna Lore
2017-03-03 00:03:31 +01:00
parent 81b53dccf3
commit b91351c5ed
2 changed files with 33 additions and 9 deletions

View File

@@ -2353,7 +2353,7 @@ class e_form
'size' => $options['switch'],
'onText' => $options_on['label'],
'offText' => $options_off['label'],
'inverse' => !empty($options['inverse']),
),
);
@@ -2362,12 +2362,12 @@ class e_form
$js_options[$name]['wrapperClass'] = 'wrapper form-control';
}
e107::library('load', 'bootstrap.switch');
e107::js('settings', array('bsSwitch' => $js_options));
e107::js('footer', '{e_WEB}js/bootstrap.switch.init.js', 'jquery', 5);
$text = $this->checkbox($name, 1, $checked_enabled);
$text = $this->hidden($name, (int) $checked_enabled);
$text .= $this->checkbox($name, 1, $checked_enabled);
}
elseif(!empty($options['inverse'])) // Same as 'writeParms'=>'reverse=1&enabled=LAN_DISABLED&disabled=LAN_ENABLED'
{

View File

@@ -18,12 +18,36 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
{
$('input[name="' + name + '"]', context).once('bootstrap-switch-init').each(function ()
{
$(this).bootstrapSwitch({
size: options.size || 'mini',
onText: options.onText || null,
offText: options.offText || null,
wrapperClass: options.wrapperClass || null
});
if($(this).attr('type') != 'hidden')
{
$(this).bootstrapSwitch({
size: options.size || 'mini',
onText: options.onText || null,
offText: options.offText || null,
wrapperClass: options.wrapperClass || null
});
$(this).on('switchChange.bootstrapSwitch', function (event, state) {
var name = $(this).attr('name');
var checked = true;
if(state === false)
{
checked = false;
}
var value = checked ? 1 : 0;
if(options.inverse)
{
// value = checked ? 0 : 1;
}
$('input[type="hidden"][name="' + name + '"]').val(value);
event.preventDefault();
});
}
});
});
}