* fixes #726

* Disabled Sumit butto nif form is not touched & used tri function instead of replace
This commit is contained in:
Nitesh Sawant 2018-10-23 01:11:35 +05:30 committed by Cassie Tarakajian
parent 55dfd7e328
commit 121bf94007
2 changed files with 27 additions and 7 deletions

View file

@ -13,13 +13,16 @@ class NewFolderForm extends React.Component {
}
render() {
const { fields: { name }, handleSubmit } = this.props;
const {
fields: { name }, handleSubmit, submitting, pristine
} = this.props;
return (
<form
className="new-folder-form"
onSubmit={(data) => {
handleSubmit(this.createFolder)(data);
if (handleSubmit(this.createFolder)(data)) {
this.props.closeModal();
}
}}
>
<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; }}
{...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>
);
}
@ -43,7 +47,12 @@ NewFolderForm.propTypes = {
}).isRequired,
handleSubmit: 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;

View file

@ -32,7 +32,18 @@ NewFolderModal.propTypes = {
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({
form: 'new-folder',
fields: ['name']
fields: ['name'],
validate
})(NewFolderModal);