Skip to content

A platform for community discussion. Free, open, simple.

FIX: Disable save button when new group form is empty.

Guo Xiang Tanc0595ebe995b
diff --git a/app/assets/javascripts/discourse/components/groups-form-profile-fields.js.es6 b/app/assets/javascripts/discourse/components/groups-form-profile-fields.js.es6
index 0c268b265e9..c62f7710981 100644
--- a/app/assets/javascripts/discourse/components/groups-form-profile-fields.js.es6
+++ b/app/assets/javascripts/discourse/components/groups-form-profile-fields.js.es6
@@ -4,13 +4,18 @@ import InputValidation from 'discourse/models/input-validation';
import debounce from 'discourse/lib/debounce';
export default Ember.Component.extend({
- saving: null,
+ disableSave: null,
nameInput: null,
didInsertElement() {
this._super();
const name = this.get('model.name');
- if (name) this.set("nameInput", name);
+
+ if (name) {
+ this.set("nameInput", name);
+ } else {
+ this.set('disableSave', true);
+ }
},
@computed('basicNameValidation', 'uniqueNameValidation')
@@ -58,7 +63,7 @@ export default Ember.Component.extend({
reason: I18n.t('admin.groups.new.name.available')
}));
- this.set('saving', false);
+ this.set('disableSave', false);
this.set('model.name', this.get('nameInput'));
} else {
let reason;
@@ -75,7 +80,7 @@ export default Ember.Component.extend({
}, 500),
_failedInputValidation(reason) {
- this.set('saving', true);
+ this.set('disableSave', true);
const options = { failed: true };
if (reason) options.reason = reason;
diff --git a/app/assets/javascripts/discourse/templates/group/manage/profile.hbs b/app/assets/javascripts/discourse/templates/group/manage/profile.hbs
index 394d17c8b73..4c4ab73ba1d 100644
--- a/app/assets/javascripts/discourse/templates/group/manage/profile.hbs
+++ b/app/assets/javascripts/discourse/templates/group/manage/profile.hbs
@@ -1,4 +1,4 @@
<form class="groups-form form-vertical">
- {{groups-form-profile-fields model=model saving=saving}}
+ {{groups-form-profile-fields model=model disableSave=saving}}
{{group-manage-save-button model=model saving=saving}}
</form>
diff --git a/app/assets/javascripts/discourse/templates/groups/new.hbs b/app/assets/javascripts/discourse/templates/groups/new.hbs
index 523a07ff5d6..2501e0be9f0 100644
--- a/app/assets/javascripts/discourse/templates/groups/new.hbs
+++ b/app/assets/javascripts/discourse/templates/groups/new.hbs
@@ -4,7 +4,7 @@
<hr/>
<form class="groups-form form-vertical">
- {{#groups-form-profile-fields model=model saving=saving}}
+ {{#groups-form-profile-fields model=model disableSave=saving}}
<div class="control-group">
<label class="control-label" for="owner-selector">{{i18n 'admin.groups.add_owners'}}</label>
diff --git a/test/javascripts/acceptance/groups-new-test.js.es6 b/test/javascripts/acceptance/groups-new-test.js.es6
index a203082dd3e..423f189abd9 100644
--- a/test/javascripts/acceptance/groups-new-test.js.es6
+++ b/test/javascripts/acceptance/groups-new-test.js.es6
@@ -7,8 +7,8 @@ QUnit.test("As an anon user", assert => {
andThen(() => {
assert.equal(
- find('.groups-admin-dropdown').length, 0,
- 'it should not display the admin dropdown'
+ find('.groups-header-new').length, 0,
+ 'it should not display the button to create a group'
);
});
});
@@ -20,6 +20,14 @@ QUnit.test("Creating a new group", assert => {
visit("/groups");
click(".groups-header-new");
+
+ andThen(() => {
+ assert.equal(
+ find('.group-form-save[disabled]').length, 1,
+ 'save button should be disabled'
+ );
+ });
+
fillIn("input[name='name']", '1');
andThen(() => {