From 8c4003bb17b9d81b1dad58cbdc3e8daffe511858 Mon Sep 17 00:00:00 2001 From: catarak Date: Wed, 3 Aug 2016 17:42:58 -0400 Subject: [PATCH] add rename validation --- client/modules/IDE/components/SidebarItem.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client/modules/IDE/components/SidebarItem.js b/client/modules/IDE/components/SidebarItem.js index 4a00c8dd..efec5e0a 100644 --- a/client/modules/IDE/components/SidebarItem.js +++ b/client/modules/IDE/components/SidebarItem.js @@ -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} /> { + this.originalFileName = this.props.file.name; this.props.showEditFileName(this.props.file.id); setTimeout(() => this.refs.fileNameInput.focus(), 0); }}