Skip to content

Let data-show-time turn time off as well as on - #19

Merged
Fivell merged 2 commits into
masterfrom
fix/show-time-false
Oct 1, 2026
Merged

Fivell merged 2 commits into
masterfrom
fix/show-time-false

Conversation

@Fivell

@Fivell Fivell commented Oct 1, 2026

Copy link
Copy Markdown
Member

Follow-up to #13, which made show_time element-scoped. This fixes the half that was never reachable before that landed.

The bug

if (typeof $this.data('show-time') != 'undefined' && $this.data('show-time').toString() == 'true') {
  el_opts.show_time = true;
}

The attribute is write-only. The guard reads it, compares to "true", and assigns true. There is no branch that assigns false. So data-show-time can only ever add time, never remove it.

That matters as soon as show_time is on at a level above the element — either $.fn.date_range_ext_preset.defaults.show_time = true, which the README documents, or passed to the call:

$('.filter_date_range').date_range_ext_preset({ show_time: true });

Every matched input now gets datetimes, and data-show-time="false" on one of them is a no-op. There is no way to opt out.

This was latent until #13: before it, show_time was shared across the whole call anyway, so one element could not have differed from another regardless.

The fix

Make the attribute authoritative in both directions when it is present:

if (typeof $this.data('show-time') != 'undefined') {
  el_opts.show_time = $this.data('show-time').toString() == 'true';
}

Absent attribute still inherits from the call and the defaults, so nothing that worked before changes.

The spec

The fixture gains an input wrapped in manual_preset_pair rather than datetime_preset_pair, so the plugin's auto-init leaves it alone and the example can call the plugin with { show_time: true } without a second "Set range" link getting in the way.

On the parent commit:

expected: "2026-10-02"
     got: "2026-10-02 00:00:00"

Fivell added 2 commits October 1, 2026 12:59
The attribute is write-only. The guard reads it, compares to "true", and
assigns true; there is no branch that assigns false. So it can only ever
add time, never remove it, and an input that wants dates inside a call that
asked for datetimes has no way to say so.

The fixture gains a pair outside .datetime_preset_pair, which the auto-init
leaves alone, so the example can drive it with explicit options without a
second "Set range" link getting in the way.

This commit is expected to fail CI.
Assign the attribute's value rather than a bare true, so an element can opt
out of a show_time its call or the defaults turned on. An absent attribute
still inherits, so nothing that worked before changes.

Unreachable before per-element options landed: show_time was shared across
the whole call, so one element could not have differed from another anyway.
@Fivell
Fivell force-pushed the fix/show-time-false branch from 31eea92 to 81fab99 Compare October 1, 2026 11:00
@Fivell
Fivell merged commit ede2920 into master Oct 1, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant