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