From 8a814c287cd6dc85fbd63cb29518ac0e21aabfb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 18 Aug 2015 17:57:14 +0200 Subject: [PATCH] form validation first cut --- js/components/ascribe_forms/form.js | 41 +++++++++++-- .../ascribe_forms/form_register_piece.js | 58 +++++++++++++------ js/components/ascribe_forms/input_checkbox.js | 27 +++++---- js/components/ascribe_forms/property.js | 43 +++++++++++--- .../cyland/cyland_register_piece.js | 3 +- 5 files changed, 131 insertions(+), 41 deletions(-) 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 (
{this.props.headerMessage} + name="digital_work_key" + ignoreFocus={true} + required={true}> + label={getLangText('Artist Name')} + required={true}> + label={getLangText('Title')} + required={true}> + label={getLangText('Year Created')} + required={true}> + style={{paddingBottom: 0}} + required={true}> {' ' + getLangText('I agree to the Terms of Service of Cyland Archive') + ' '}