Skip to content

Commit 121bf94

Browse files
ns23catarak
authored andcommitted
fixes #726 (#728)
* fixes #726 * Disabled Sumit butto nif form is not touched & used tri function instead of replace
1 parent 55dfd7e commit 121bf94

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

client/modules/IDE/components/NewFolderForm.jsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ class NewFolderForm extends React.Component {
1313
}
1414

1515
render() {
16-
const { fields: { name }, handleSubmit } = this.props;
16+
const {
17+
fields: { name }, handleSubmit, submitting, pristine
18+
} = this.props;
1719
return (
1820
<form
1921
className="new-folder-form"
2022
onSubmit={(data) => {
21-
handleSubmit(this.createFolder)(data);
22-
this.props.closeModal();
23+
if (handleSubmit(this.createFolder)(data)) {
24+
this.props.closeModal();
25+
}
2326
}}
2427
>
2528
<label className="new-folder-form__name-label" htmlFor="name">Name:</label>
@@ -31,7 +34,8 @@ class NewFolderForm extends React.Component {
3134
ref={(element) => { this.fileName = element; }}
3235
{...domOnlyProps(name)}
3336
/>
34-
<input type="submit" value="Add Folder" aria-label="add folder" />
37+
<input type="submit" value="Add Folder" disabled={submitting || pristine} aria-label="add folder" />
38+
{name.touched && name.error && <span className="form-error">{name.error}</span>}
3539
</form>
3640
);
3741
}
@@ -43,7 +47,12 @@ NewFolderForm.propTypes = {
4347
}).isRequired,
4448
handleSubmit: PropTypes.func.isRequired,
4549
createFolder: PropTypes.func.isRequired,
46-
closeModal: PropTypes.func.isRequired
50+
closeModal: PropTypes.func.isRequired,
51+
submitting: PropTypes.bool,
52+
pristine: PropTypes.bool
53+
};
54+
NewFolderForm.defaultProps = {
55+
submitting: false,
56+
pristine: true
4757
};
48-
4958
export default NewFolderForm;

client/modules/IDE/components/NewFolderModal.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,18 @@ NewFolderModal.propTypes = {
3232
closeModal: PropTypes.func.isRequired
3333
};
3434

35+
function validate(formProps) {
36+
const errors = {};
37+
if (!formProps.name) {
38+
errors.name = 'Please enter a name';
39+
} else if (formProps.name.trim().length === 0) {
40+
errors.name = 'Folder name cannot contain only spaces';
41+
}
42+
43+
return errors;
44+
}
3545
export default reduxForm({
3646
form: 'new-folder',
37-
fields: ['name']
47+
fields: ['name'],
48+
validate
3849
})(NewFolderModal);

0 commit comments

Comments
 (0)