add rename validation

This commit is contained in:
catarak 2016-08-03 17:42:58 -04:00
parent 443a9f57d5
commit 8c4003bb17

View file

@ -8,6 +8,7 @@ class SidebarItem extends React.Component {
super(props);
this.handleKeyPress = this.handleKeyPress.bind(this);
this.handleFileNameChange = this.handleFileNameChange.bind(this);
this.validateFileName = this.validateFileName.bind(this);
}
handleFileNameChange(event) {
@ -21,6 +22,12 @@ class SidebarItem extends React.Component {
}
}
validateFileName() {
if (!this.props.file.name.match(/.*\.(js|css|html|json)$/)) {
this.props.updateFileName(this.props.file.id, this.originalFileName);
}
}
render() {
let itemClass = classNames({
'sidebar__file-item': true,
@ -45,7 +52,10 @@ class SidebarItem extends React.Component {
value={this.props.file.name}
onChange={this.handleFileNameChange}
ref="fileNameInput"
onBlur={() => this.props.hideEditFileName(this.props.file.id)}
onBlur={() => {
this.validateFileName();
this.props.hideEditFileName(this.props.file.id);
}}
onKeyPress={this.handleKeyPress}
/>
<a
@ -59,6 +69,7 @@ class SidebarItem extends React.Component {
<li>
<a
onClick={() => {
this.originalFileName = this.props.file.name;
this.props.showEditFileName(this.props.file.id);
setTimeout(() => this.refs.fileNameInput.focus(), 0);
}}