UX: Wiggle invalid form elements. Don't allow a site title of Discourse

This commit is contained in:
Robin Ward 2016-09-15 16:01:44 -04:00
parent 2ff6295f71
commit 74ed2e82ac
4 changed files with 33 additions and 2 deletions

View File

@ -1,5 +1,16 @@
import { default as computed, observes } from 'ember-addons/ember-computed-decorators'; 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({ export default Ember.Component.extend({
classNames: ['wizard-step'], classNames: ['wizard-step'],
saving: null, saving: null,
@ -51,6 +62,10 @@ export default Ember.Component.extend({
}); });
}, },
animateInvalidFields() {
Ember.run.scheduleOnce('afterRender', () => $('.invalid input[type=text]').wiggle(2, 100));
},
actions: { actions: {
quit() { quit() {
document.location = "/"; document.location = "/";
@ -71,9 +86,10 @@ export default Ember.Component.extend({
this.set('saving', true); this.set('saving', true);
step.save() step.save()
.then(response => this.sendAction('goNext', response)) .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)); .finally(() => this.set('saving', false));
} else { } else {
this.animateInvalidFields();
this.autoFocus(); this.autoFocus();
} }
} }

View File

@ -30,9 +30,13 @@ class Wizard
step.add_field(id: 'site_description', type: 'text', required: true, value: SiteSetting.site_description) step.add_field(id: 'site_description', type: 'text', required: true, value: SiteSetting.site_description)
step.on_update do |updater| step.on_update do |updater|
updater.ensure_changed(:title)
if updater.errors.blank?
updater.apply_settings(:title, :site_description) updater.apply_settings(:title, :site_description)
end end
end end
end
@wizard.append_step('privacy') do |step| @wizard.append_step('privacy') do |step|
locked = SiteSetting.login_required? && SiteSetting.invite_only? locked = SiteSetting.login_required? && SiteSetting.invite_only?

View File

@ -39,6 +39,10 @@ class Wizard
errors.add(id, e.message) errors.add(id, e.message)
end end
def ensure_changed(id)
errors.add(id, '') if @fields[id] == SiteSetting.defaults[id]
end
def apply_settings(*ids) def apply_settings(*ids)
ids.each {|id| apply_setting(id)} ids.each {|id| apply_setting(id)}
end end

View File

@ -38,6 +38,13 @@ describe Wizard::StepUpdater do
expect(wizard.completed_steps?('forum-title')).to eq(true) expect(wizard.completed_steps?('forum-title')).to eq(true)
end 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 context "privacy settings" do
it "updates to open correctly" do it "updates to open correctly" do
updater = wizard.create_updater('privacy', privacy: 'open') updater = wizard.create_updater('privacy', privacy: 'open')