Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions spec/per_element_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions spec/support/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions vendor/assets/javascripts/active_admin_date_range_preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading