Only validate new team modal input when save has been clicked

This commit is contained in:
Jonas Schwabe
2017-01-30 20:45:47 +01:00
parent be2db91d05
commit c36f7f795d
2 changed files with 25 additions and 9 deletions

View File

@@ -8,11 +8,15 @@ class NewTeamModal extends React.Component {
super(); super();
this.state = { this.state = {
teamName: '', teamName: '',
teamUrl: '' teamUrl: '',
saveStarted: false
}; };
} }
getTeamNameValidationState() { getTeamNameValidationState() {
if (!this.state.saveStarted) {
return '';
}
return this.state.teamName.length > 0 ? '' : 'error'; return this.state.teamName.length > 0 ? '' : 'error';
} }
@@ -23,6 +27,9 @@ class NewTeamModal extends React.Component {
} }
getTeamUrlValidationState() { getTeamUrlValidationState() {
if (!this.state.saveStarted) {
return '';
}
if (this.state.teamUrl.length === 0) { if (this.state.teamUrl.length === 0) {
return 'error'; return 'error';
} }
@@ -44,12 +51,16 @@ class NewTeamModal extends React.Component {
} }
save() { save() {
if (this.validateForm()) { this.setState({
this.props.onSave({ saveStarted: true
url: this.state.teamUrl, }, () => {
name: this.state.teamName if (this.validateForm()) {
}); this.props.onSave({
} url: this.state.teamUrl,
name: this.state.teamName
});
}
});
} }
render() { render() {

View File

@@ -266,18 +266,21 @@ describe('browser/settings.html', function desc() {
it('should not be valid if no team name has been set', () => { it('should not be valid if no team name has been set', () => {
return this.app.client. return this.app.client.
click('#saveNewServerModal').
isExisting('.has-error #teamNameInput').should.eventually.equal(true); isExisting('.has-error #teamNameInput').should.eventually.equal(true);
}); });
it('should not be valid if no server address has been set', () => { it('should not be valid if no server address has been set', () => {
return this.app.client. return this.app.client.
click('#saveNewServerModal').
isExisting('.has-error #teamUrlInput').should.eventually.equal(true); isExisting('.has-error #teamUrlInput').should.eventually.equal(true);
}); });
describe('Valid server name', () => { describe('Valid server name', () => {
beforeEach(() => { beforeEach(() => {
return this.app.client. return this.app.client.
setValue('#teamNameInput', 'TestTeam'); setValue('#teamNameInput', 'TestTeam').
click('#saveNewServerModal');
}); });
it('should not be marked invalid', () => { it('should not be marked invalid', () => {
@@ -294,7 +297,8 @@ describe('browser/settings.html', function desc() {
describe('Valid server url', () => { describe('Valid server url', () => {
beforeEach(() => { beforeEach(() => {
return this.app.client. return this.app.client.
setValue('#teamUrlInput', 'http://example.org'); setValue('#teamUrlInput', 'http://example.org').
click('#saveNewServerModal');
}); });
it('should be valid', () => { it('should be valid', () => {
@@ -311,6 +315,7 @@ describe('browser/settings.html', function desc() {
it('should not be valid if an invalid server address has been set', () => { it('should not be valid if an invalid server address has been set', () => {
return this.app.client. return this.app.client.
setValue('#teamUrlInput', 'superInvalid url'). setValue('#teamUrlInput', 'superInvalid url').
click('#saveNewServerModal').
isExisting('.has-error #teamUrlInput').should.eventually.equal(true); isExisting('.has-error #teamUrlInput').should.eventually.equal(true);
}); });