Merge pull request #7697 from jibees/7689-trigger-a-change-when-hour/minute-inputs-are-modified

Datetimepicker for order cycles: add keyup event listener on hour/minute inputs
This commit is contained in:
Andy Brett
2021-06-08 10:32:07 -07:00
committed by GitHub
2 changed files with 17 additions and 1 deletions

View File

@@ -3,12 +3,18 @@ angular.module('admin.orderCycles', ['ngTagsInput', 'admin.indexUtils', 'admin.e
require: "ngModel"
link: (scope, element, attrs, ngModel) ->
$timeout ->
flatpickr(element, Object.assign({},
fp = flatpickr(element, Object.assign({},
window.FLATPICKR_DATETIME_DEFAULT, {
onOpen: (selectedDates, dateStr, instance) ->
instance.setDate(ngModel.$modelValue)
instance.input.dispatchEvent(new Event('focus', { bubbles: true }));
}));
fp.minuteElement.addEventListener "keyup", (e) ->
if !isNaN(event.target.value)
fp.setDate(fp.selectedDates[0].setMinutes(e.target.value), true)
fp.hourElement.addEventListener "keyup", (e) ->
if !isNaN(event.target.value)
fp.setDate(fp.selectedDates[0].setHours(e.target.value), true)
.directive 'ofnOnChange', ->
(scope, element, attrs) ->

View File

@@ -604,6 +604,16 @@ feature '
end
end
scenario "modify the minute of a order cycle with the keyboard, check that the modifications are taken into account" do
order_cycle = create(:simple_order_cycle, name: "Translusent Berries")
login_as_admin_and_visit admin_order_cycles_path
find("#oc#{order_cycle.id}_orders_close_at").click
datetime = Time.at(Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0))
input = find(".flatpickr-calendar.open .flatpickr-minute")
input.send_keys datetime.strftime("%M").to_s.strip
expect(page).to have_content "You have unsaved changes"
end
scenario "deleting an order cycle" do
order_cycle = create(:simple_order_cycle, name: "Translusent Berries")
login_as_admin_and_visit admin_order_cycles_path