From 81fab9963bef6ffc367d71da10ca374b968f0c52 Mon Sep 17 00:00:00 2001 From: Igor Fedoronchuk Date: Thu, 1 Oct 2026 12:59:23 +0200 Subject: [PATCH 1/2] Show data-show-time="false" cannot turn time off 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. --- spec/per_element_options_spec.rb | 12 ++++++++++++ spec/support/admin.rb | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/spec/per_element_options_spec.rb b/spec/per_element_options_spec.rb index 69c7d54..0e77a80 100644 --- a/spec/per_element_options_spec.rb +++ b/spec/per_element_options_spec.rb @@ -27,4 +27,16 @@ def value_of(wrapper_id) expect(value_of('post_created_at_input')).to eq(today.strftime('%Y-%m-%d 00:00:00')) end + + # show_time passed to the call is the documented way to turn time on for a + # group of inputs. data-show-time="false" is then the only way for one of + # them to opt out, and the attribute was write-only: the guard assigned + # true and never false. + it 'lets data-show-time="false" opt back out of a call that asked for time' do + page.execute_script("$('.manual_preset_pair').date_range_ext_preset({ show_time: true });") + + pick_today_in('post_title_input') + + expect(value_of('post_title_input')).to eq((today + 1).strftime('%Y-%m-%d')) + end end diff --git a/spec/support/admin.rb b/spec/support/admin.rb index 2548392..e6f62d1 100644 --- a/spec/support/admin.rb +++ b/spec/support/admin.rb @@ -37,6 +37,10 @@ def add_post_resource_with_two_pairs f.input :created_at, as: :string, wrapper_html: { class: 'datetime_preset_pair', data: { show_time: 'true' } } f.input :updated_at, as: :string + # Not .datetime_preset_pair, so the auto-init leaves it alone and the + # spec can drive it with explicit options. + f.input :title, as: :string, + wrapper_html: { class: 'manual_preset_pair', data: { show_time: 'false' } } end f.actions end From 31eea921c291e25b01b1f1c104f69c080256161a Mon Sep 17 00:00:00 2001 From: Igor Fedoronchuk Date: Thu, 1 Oct 2026 13:00:03 +0200 Subject: [PATCH 2/2] Let data-show-time turn time off as well as on 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. --- .../assets/javascripts/active_admin_date_range_preset.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vendor/assets/javascripts/active_admin_date_range_preset.js b/vendor/assets/javascripts/active_admin_date_range_preset.js index 4ed2d9a..ad2a75e 100644 --- a/vendor/assets/javascripts/active_admin_date_range_preset.js +++ b/vendor/assets/javascripts/active_admin_date_range_preset.js @@ -60,8 +60,11 @@ $(function () { // click time rather than here, so the leak was not even order-dependent. let el_opts = $.extend({}, opts); - if (typeof $this.data('show-time') != 'undefined' && $this.data('show-time').toString() == 'true') { - el_opts.show_time = true; + // The attribute is authoritative in both directions when present. Only + // ever assigning true made it impossible for one element to opt out of + // a show_time the call or the defaults had turned on. + if (typeof $this.data('show-time') != 'undefined') { + el_opts.show_time = $this.data('show-time').toString() == 'true'; } // detect inputs