[Ovmsdev] Slider widget not disabled when first loading unchecked?
Michael Balzer
dexter at expeedo.de
Tue Dec 27 15:54:24 HKT 2022
Michael,
I remember I changed the slider enable/disable control scheme from
reading the checkbox state to using the data attribute / option for a
reason, but I cannot remember exactly which now. I think it was to get
consistent dynamic controllability.
My initial commit was ec1a874dadce01e8bd588c20115d890acd9149c2, which
used the checkbox state. A few days later in
91ed78a3d7ac5392eadd65be026a1a0fc77a611e I changed this to using the
`checked` option, but missed adding `data-checked` to
`PageContext::input_slider()` accordingly.
Sliders using the enable/disable feature at that time only appeared in
plugins/pages doing dynamic initialization, so this didn't become
visible. Plugins normally create sliders by data attributes or init
options, not by explicit markup.
TL;DR: I think the fix would probably better be to add the missing
`data-checked` to the markup created by `PageContext::input_slider()`.
Regards,
Michael
Am 27.12.22 um 04:40 schrieb Michael Geddes:
> Right, so that didn't work if the check-box was disabled (like in
> wifi)- but this does seem to work!
>
> var $sld = $(this).closest('.slider'), $cbi =
> $sld.find('.slider-enable'), data = $.extend({ checked:
> ($cbi.prop("type") === "hidden" || $cbi.prop("checked")) }, $sld.data());
>
> //.ichael
>
> On Tue, 27 Dec 2022 at 11:04, Michael Geddes
> <frog at bunyip.wheelycreek.net> wrote:
>
> Hi all,
> I've noticed that if you create a 'slider' widget with a checkbox
> that if it's unchecked when it first loads, then the slider is
> enabled. If you check/uncheck then the slider is disabled. Or at
> least that's what I seen in google chrome.
>
> I'm really not familiar with NodeJS, but this _seems_ to fix the
> problem:
>
> Does this fix make sense? If so - I'll do a p/r for it.
>
> //.ichael
>
>
> * Slider widget plugin
> */
>
> $.fn.slider = function(options) {
> return this.each(function() {
> - var $sld = $(this).closest('.slider'), data = $.extend({
> checked: true }, $sld.data());
> + var $sld = $(this).closest('.slider'), $cbi =
> $sld.find('.slider-enable'), data = $.extend({ checked:
> $cbi.prop("checked") }, $sld.data());
> var opts = (typeof options == "object") ? options : data;
> // init?
> if ($sld.children().length == 0) {
> var id = $sld.attr('id');
> $sld.html('\
>
>
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.openvehicles.com
> http://lists.openvehicles.com/mailman/listinfo/ovmsdev
--
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20221227/63c91b69/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 203 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20221227/63c91b69/attachment.sig>
More information about the OvmsDev
mailing list