From 74ed2e82ac2bd31f8116ccdf9fa8ead020f037dc Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 15 Sep 2016 16:01:44 -0400 Subject: [PATCH] UX: Wiggle invalid form elements. Don't allow a site title of Discourse --- .../wizard/components/wizard-step.js.es6 | 18 +++++++++++++++++- lib/wizard/builder.rb | 6 +++++- lib/wizard/step_updater.rb | 4 ++++ spec/components/step_updater_spec.rb | 7 +++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/wizard/components/wizard-step.js.es6 b/app/assets/javascripts/wizard/components/wizard-step.js.es6 index 39af7c43aa9..c9bd8e02c68 100644 --- a/app/assets/javascripts/wizard/components/wizard-step.js.es6 +++ b/app/assets/javascripts/wizard/components/wizard-step.js.es6 @@ -1,5 +1,16 @@ import { default as computed, observes } from 'ember-addons/ember-computed-decorators'; +jQuery.fn.wiggle = function (times, duration) { + if (times > 0) { + this.animate({ + marginLeft: times-- % 2 === 0 ? -15 : 15 + }, duration, 0, () => this.wiggle(times, duration)); + } else { + this.animate({ marginLeft: 0 }, duration, 0); + } + return this; +}; + export default Ember.Component.extend({ classNames: ['wizard-step'], saving: null, @@ -51,6 +62,10 @@ export default Ember.Component.extend({ }); }, + animateInvalidFields() { + Ember.run.scheduleOnce('afterRender', () => $('.invalid input[type=text]').wiggle(2, 100)); + }, + actions: { quit() { document.location = "/"; @@ -71,9 +86,10 @@ export default Ember.Component.extend({ this.set('saving', true); step.save() .then(response => this.sendAction('goNext', response)) - .catch(() => null) // we can swallow because the form is already marked as invalid + .catch(() => this.animateInvalidFields()) .finally(() => this.set('saving', false)); } else { + this.animateInvalidFields(); this.autoFocus(); } } diff --git a/lib/wizard/builder.rb b/lib/wizard/builder.rb index e6f421fb1ff..120d0866f09 100644 --- a/lib/wizard/builder.rb +++ b/lib/wizard/builder.rb @@ -30,7 +30,11 @@ class Wizard step.add_field(id: 'site_description', type: 'text', required: true, value: SiteSetting.site_description) step.on_update do |updater| - updater.apply_settings(:title, :site_description) + updater.ensure_changed(:title) + + if updater.errors.blank? + updater.apply_settings(:title, :site_description) + end end end diff --git a/lib/wizard/step_updater.rb b/lib/wizard/step_updater.rb index f8ef9538c8f..f05605c33fe 100644 --- a/lib/wizard/step_updater.rb +++ b/lib/wizard/step_updater.rb @@ -39,6 +39,10 @@ class Wizard errors.add(id, e.message) end + def ensure_changed(id) + errors.add(id, '') if @fields[id] == SiteSetting.defaults[id] + end + def apply_settings(*ids) ids.each {|id| apply_setting(id)} end diff --git a/spec/components/step_updater_spec.rb b/spec/components/step_updater_spec.rb index 45c4c6f94bc..def8922823e 100644 --- a/spec/components/step_updater_spec.rb +++ b/spec/components/step_updater_spec.rb @@ -38,6 +38,13 @@ describe Wizard::StepUpdater do expect(wizard.completed_steps?('forum-title')).to eq(true) end + it "won't allow updates to the default value, when required" do + updater = wizard.create_updater('forum_title', title: SiteSetting.title, site_description: 'neat place') + updater.update + + expect(updater.success?).to eq(false) + end + context "privacy settings" do it "updates to open correctly" do updater = wizard.create_updater('privacy', privacy: 'open')