Only validate new team modal input when save has been clicked
This commit is contained in:
@@ -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() {
|
||||||
|
@@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user