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

https://meta.discourse.org/t/adding-owners-members-ux-is-inconsistent-and-misleading/58084/26?u=tgxworld
This commit is contained in:
Guo Xiang Tan 2018-04-12 10:29:09 +08:00
parent 71b2f8ae1d
commit c0595ebe99
4 changed files with 21 additions and 8 deletions

View File

@ -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;

View File

@ -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>

View File

@ -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>

View File

@ -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(() => {