mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
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:
@@ -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) ->
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user