diff --git a/js/components/ascribe_forms/form.js b/js/components/ascribe_forms/form.js index 2b956a7e..a9e267d9 100644 --- a/js/components/ascribe_forms/form.js +++ b/js/components/ascribe_forms/form.js @@ -23,8 +23,8 @@ let Form = React.createClass({ handleSuccess: React.PropTypes.func, getFormData: React.PropTypes.func, children: React.PropTypes.oneOfType([ - React.PropTypes.object, - React.PropTypes.array + React.PropTypes.arrayOf(React.PropTypes.element), + React.PropTypes.element ]), className: React.PropTypes.string, spinner: React.PropTypes.element, @@ -165,14 +165,43 @@ let Form = React.createClass({ this.setState({errors: []}); }, + checkFormValidity() { + let requiredProps = []; + + Object + .keys(this.refs) + .forEach((refName) => { + if(this.refs[refName].props.required) { + requiredProps.push(this.refs[refName]); + } + }); + + let validProps = requiredProps.filter((property) => property.state.isValid); + + if(requiredProps.length === validProps.length) { + return true; + } else { + return false; + } + + }, + getButtons() { - if (this.state.submitted){ + let buttons = null; + let isFormValid = this.checkFormValidity(); + + if(this.state.submitted) { return this.props.spinner; } - if (this.props.buttons){ - return this.props.buttons; + if(this.props.buttons) { + + buttons = React.cloneElement(this.props.buttons, { + disabled: !isFormValid + }); + + return buttons; } - let buttons = null; + if (this.state.edited){ buttons = ( diff --git a/js/components/ascribe_forms/form_register_piece.js b/js/components/ascribe_forms/form_register_piece.js index 6545007c..ef25dd55 100644 --- a/js/components/ascribe_forms/form_register_piece.js +++ b/js/components/ascribe_forms/form_register_piece.js @@ -27,7 +27,10 @@ let RegisterPieceForm = React.createClass({ isFineUploaderActive: React.PropTypes.bool, isFineUploaderEditable: React.PropTypes.bool, enableLocalHashing: React.PropTypes.bool, - children: React.PropTypes.element, + children: React.PropTypes.oneOfType([ + React.PropTypes.arrayOf(React.PropTypes.element), + React.PropTypes.element + ]), onLoggedOut: React.PropTypes.func }, @@ -74,16 +77,11 @@ let RegisterPieceForm = React.createClass({ }); }, - setIsUploadReady(isReady) { - this.setState({ - isUploadReady: isReady - }); - }, - render() { let currentUser = this.state.currentUser; let enableLocalHashing = currentUser && currentUser.profile ? currentUser.profile.hash_locally : false; enableLocalHashing = enableLocalHashing && this.props.enableLocalHashing; + return (