From b58225a19a8b838a64cece954ca8eb594481db01 Mon Sep 17 00:00:00 2001 From: Mantas Date: Mon, 17 Aug 2020 13:03:40 +0300 Subject: [PATCH] Fixes #2887 - Entering pending till time for Waiting status is difficult to enter with Firefox --- .../app/lib/bootstrap/bootstrap-timepicker.js | 4 ++- app/views/tests/form_datetime.html.erb | 21 ++++++++++++++ config/routes/test.rb | 1 + public/assets/tests/form_datetime.js | 29 +++++++++++++++++++ spec/system/js/q_unit_spec.rb | 4 +++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 app/views/tests/form_datetime.html.erb create mode 100644 public/assets/tests/form_datetime.js diff --git a/app/assets/javascripts/app/lib/bootstrap/bootstrap-timepicker.js b/app/assets/javascripts/app/lib/bootstrap/bootstrap-timepicker.js index ac9667711..c61d5d941 100644 --- a/app/assets/javascripts/app/lib/bootstrap/bootstrap-timepicker.js +++ b/app/assets/javascripts/app/lib/bootstrap/bootstrap-timepicker.js @@ -111,11 +111,13 @@ } this.setDefaultTime(this.defaultTime); + this.blurElement() }, blurElement: function() { this.highlightedUnit = null; this.updateFromElementVal(); + this.$element.get(0).setSelectionRange(0,0) }, clear: function() { @@ -259,7 +261,7 @@ switch (this.getCursorPosition()) { case 1: // highlight minutes but async because the newly typed character is not yet stored in the value (happens after this event) - setTimeout($.proxy(this.highlightMinute, this), 0); + setTimeout($.proxy(this.highlightMinute, this), 50); break; } } diff --git a/app/views/tests/form_datetime.html.erb b/app/views/tests/form_datetime.html.erb new file mode 100644 index 000000000..b66259a08 --- /dev/null +++ b/app/views/tests/form_datetime.html.erb @@ -0,0 +1,21 @@ + + +<%= javascript_include_tag "/assets/tests/qunit-1.21.0.js", "/assets/tests/form_datetime.js", nonce: true %> + + + +<%= javascript_tag nonce: true do -%> +<% end -%> + +
+ +
+
+
+ +
+
diff --git a/config/routes/test.rb b/config/routes/test.rb index f31d43ffb..cc45d1b7d 100644 --- a/config/routes/test.rb +++ b/config/routes/test.rb @@ -22,6 +22,7 @@ Zammad::Application.routes.draw do match '/tests_form_ticket_perform_action', to: 'tests#form_ticket_perform_action', via: :get match '/tests_form_sla_times', to: 'tests#form_sla_times', via: :get match '/tests_form_skip_rendering', to: 'tests#form_skip_rendering', via: :get + match '/tests_form_datetime', to: 'tests#form_datetime', via: :get match '/tests_table', to: 'tests#table', via: :get match '/tests_table_extended', to: 'tests#table_extended', via: :get match '/tests_html_utils', to: 'tests#html_utils', via: :get diff --git a/public/assets/tests/form_datetime.js b/public/assets/tests/form_datetime.js new file mode 100644 index 000000000..4cdc3d62a --- /dev/null +++ b/public/assets/tests/form_datetime.js @@ -0,0 +1,29 @@ +test("DateTime timepicker focuses hours", function(assert) { + var done = assert.async(1) + + var form = $('#forms') + + var el = $('
').attr('id', 'form1') + el.appendTo(form) + + new App.ControllerForm({ + el: el, + model: { + configure_attributes: [ + { name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true }, + ] + }, + autofocus: true + }); + + let timepicker = el.find('[data-item=time]') + + timepicker.focus() + + setTimeout(function(){ // give it time to apply focus + equal(timepicker[0].selectionStart, 0) + equal(timepicker[0].selectionEnd, 2) + + done() + }, 100) +}); diff --git a/spec/system/js/q_unit_spec.rb b/spec/system/js/q_unit_spec.rb index 3bf06d174..94d05234d 100644 --- a/spec/system/js/q_unit_spec.rb +++ b/spec/system/js/q_unit_spec.rb @@ -121,6 +121,10 @@ RSpec.describe 'QUnit', type: :system, authenticated_as: false, set_up: true, we it 'SLA times' do q_unit_tests('form_sla_times') end + + it 'DateTime' do + q_unit_tests('form_datetime') + end end context 'Table' do