diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee index e613a8dc9..ab58894d1 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee @@ -75,6 +75,9 @@ class App.TicketZoomArticleNew extends App.Controller if data.position is 'end' @placeCaretAtEnd(@textarea.get(0)) return + + # fixes email validation issue right after new ticket creation + @tokanice(data.type.name) ) # add article attachment diff --git a/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js b/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js index 72e8c2437..08339f039 100644 --- a/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js +++ b/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js @@ -6,6 +6,9 @@ * Edit: Felix * - remove maxTokenWidth * + * Edit: Romit + * - allow to remove token by clearing it's text manually + * */ (function (factory) { @@ -233,7 +236,10 @@ this.$element.trigger(createEvent) // Bail out if there if attributes are empty or event was defaultPrevented - if (!createEvent.attrs || createEvent.isDefaultPrevented()) return + if (!createEvent.attrs || createEvent.isDefaultPrevented()) { + this.updateTokensOnEditDiscard(triggerChange) + return + } var $token = $('
') .append('') @@ -303,10 +309,21 @@ return this.$element.get(0) } + , updateTokensOnEditDiscard: function(triggerChange) { + // if the field is being edited, update original field's value + if(this.$input.data('edit') && triggerChange) { + // Trigger change event on the original field + this.$element.val( this.getTokensList() ).trigger( $.Event('change', { initiator: 'tokenfield' }) ) + } + } + , setTokens: function (tokens, add, triggerChange) { if (!add) this.$wrapper.find('.token').remove() - if (!tokens) return + if (!tokens) { + this.updateTokensOnEditDiscard(triggerChange) + return + } if (typeof triggerChange === 'undefined') { triggerChange = true diff --git a/spec/system/ticket/update/email_reply_spec.rb b/spec/system/ticket/update/email_reply_spec.rb new file mode 100644 index 000000000..c5133ee10 --- /dev/null +++ b/spec/system/ticket/update/email_reply_spec.rb @@ -0,0 +1,50 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe 'Ticket > Update > Email Reply', current_user_id: -> { current_user.id }, type: :system, time_zone: 'Europe/London' do + let(:group) { Group.find_by(name: 'Users') } + let(:ticket) { create(:ticket, group: group) } + let(:ticket_article) { create(:ticket_article, ticket: ticket, from: 'Example Name ') } + let(:customer) { create(:customer) } + let(:current_user) { customer } + + before do + visit "ticket/zoom/#{ticket_article.ticket.id}" + end + + context 'when TO field is being edited' do + + it 'shows error dialog when updated value is an invalid email' do + within(:active_content) do + click_reply + + find('.token').double_click + find('.js-to', visible: false).sibling('.token-input').set('test') + find('.js-textarea').set('welcome to the community') + find('.js-submitDropdown button.js-submit').click + + expect(page).to have_text 'Need recipient in "To" or "Cc".' + end + end + + it 'updates article when updated value is a valid email' do + within(:active_content) do + click_reply + + find('.token').double_click + find('.js-to', visible: false).sibling('.token-input').set('user@test.com') + find('.js-textarea').set('welcome to the community') + find('.js-submitDropdown button.js-submit').click + + expect(page).to have_text 'welcome to the community' + end + end + + end + + def click_reply + click '.js-ArticleAction[data-type=emailReply]' + end + +end