* fixes #726 * Disabled Sumit butto nif form is not touched & used tri function instead of replace
This commit is contained in:
parent
55dfd7e328
commit
121bf94007
2 changed files with 27 additions and 7 deletions
|
@ -13,13 +13,16 @@ class NewFolderForm extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { fields: { name }, handleSubmit } = this.props;
|
const {
|
||||||
|
fields: { name }, handleSubmit, submitting, pristine
|
||||||
|
} = this.props;
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
className="new-folder-form"
|
className="new-folder-form"
|
||||||
onSubmit={(data) => {
|
onSubmit={(data) => {
|
||||||
handleSubmit(this.createFolder)(data);
|
if (handleSubmit(this.createFolder)(data)) {
|
||||||
this.props.closeModal();
|
this.props.closeModal();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<label className="new-folder-form__name-label" htmlFor="name">Name:</label>
|
<label className="new-folder-form__name-label" htmlFor="name">Name:</label>
|
||||||
|
@ -31,7 +34,8 @@ class NewFolderForm extends React.Component {
|
||||||
ref={(element) => { this.fileName = element; }}
|
ref={(element) => { this.fileName = element; }}
|
||||||
{...domOnlyProps(name)}
|
{...domOnlyProps(name)}
|
||||||
/>
|
/>
|
||||||
<input type="submit" value="Add Folder" aria-label="add folder" />
|
<input type="submit" value="Add Folder" disabled={submitting || pristine} aria-label="add folder" />
|
||||||
|
{name.touched && name.error && <span className="form-error">{name.error}</span>}
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +47,12 @@ NewFolderForm.propTypes = {
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
handleSubmit: PropTypes.func.isRequired,
|
handleSubmit: PropTypes.func.isRequired,
|
||||||
createFolder: PropTypes.func.isRequired,
|
createFolder: PropTypes.func.isRequired,
|
||||||
closeModal: PropTypes.func.isRequired
|
closeModal: PropTypes.func.isRequired,
|
||||||
|
submitting: PropTypes.bool,
|
||||||
|
pristine: PropTypes.bool
|
||||||
|
};
|
||||||
|
NewFolderForm.defaultProps = {
|
||||||
|
submitting: false,
|
||||||
|
pristine: true
|
||||||
};
|
};
|
||||||
|
|
||||||
export default NewFolderForm;
|
export default NewFolderForm;
|
||||||
|
|
|
@ -32,7 +32,18 @@ NewFolderModal.propTypes = {
|
||||||
closeModal: PropTypes.func.isRequired
|
closeModal: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function validate(formProps) {
|
||||||
|
const errors = {};
|
||||||
|
if (!formProps.name) {
|
||||||
|
errors.name = 'Please enter a name';
|
||||||
|
} else if (formProps.name.trim().length === 0) {
|
||||||
|
errors.name = 'Folder name cannot contain only spaces';
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
export default reduxForm({
|
export default reduxForm({
|
||||||
form: 'new-folder',
|
form: 'new-folder',
|
||||||
fields: ['name']
|
fields: ['name'],
|
||||||
|
validate
|
||||||
})(NewFolderModal);
|
})(NewFolderModal);
|
||||||
|
|
Loading…
Reference in a new issue