From e087e9f332afd15bb85875b3de65b73da9ec12c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Mon, 14 Sep 2015 11:36:24 +0200 Subject: [PATCH] PR Feedback: Provide source for types, change function validation, fix bool statement in Property.js --- js/components/ascribe_forms/form.js | 12 ++++++------ js/components/ascribe_forms/property.js | 16 +++++++++------- .../ascribe_uploader/react_s3_fine_uploader.js | 2 +- js/constants/application_constants.js | 2 ++ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/js/components/ascribe_forms/form.js b/js/components/ascribe_forms/form.js index ab91f16d..6d99d2f6 100644 --- a/js/components/ascribe_forms/form.js +++ b/js/components/ascribe_forms/form.js @@ -65,12 +65,12 @@ let Form = React.createClass({ reset() { // If onReset prop is defined from outside, // notify component that a form reset is happening. - if(this.props.onReset && typeof this.props.onReset === 'function') { + if(typeof this.props.onReset === 'function') { this.props.onReset(); } for(let ref in this.refs) { - if (this.refs[ref].reset && typeof this.refs[ref].reset === 'function'){ + if(typeof this.refs[ref].reset === 'function') { this.refs[ref].reset(); } } @@ -114,7 +114,7 @@ let Form = React.createClass({ data[this.refs[ref].props.name] = this.refs[ref].state.value; } - if(this.props.getFormData && typeof this.props.getFormData === 'function') { + if(typeof this.props.getFormData === 'function') { data = mergeOptionsWithDuplicates(data, this.props.getFormData()); } @@ -126,12 +126,12 @@ let Form = React.createClass({ }, handleSuccess(response){ - if(this.props.handleSuccess && typeof this.props.handleSuccess === 'function') { + if(typeof this.props.handleSuccess === 'function') { this.props.handleSuccess(response); } for(let ref in this.refs) { - if(this.refs[ref] && this.refs[ref].handleSuccess && typeof this.refs[ref].handleSuccess === 'function'){ + if(this.refs[ref] && typeof this.refs[ref].handleSuccess === 'function'){ this.refs[ref].handleSuccess(); } } @@ -173,7 +173,7 @@ let Form = React.createClass({ clearErrors(){ for(let ref in this.refs){ - if (this.refs[ref] && this.refs[ref].clearErrors && typeof this.refs[ref].clearErrors === 'function'){ + if (this.refs[ref] && typeof this.refs[ref].clearErrors === 'function'){ this.refs[ref].clearErrors(); } } diff --git a/js/components/ascribe_forms/property.js b/js/components/ascribe_forms/property.js index 213c3fba..f446b64f 100644 --- a/js/components/ascribe_forms/property.js +++ b/js/components/ascribe_forms/property.js @@ -105,11 +105,13 @@ let Property = React.createClass({ // For some reason, if we set the value of a non HTML element (but a custom input), // after a reset, the value will be be propagated to this component. + // // Therefore we have to make sure only to reset the initial value - // of HTML inputs. + // of HTML inputs (which we determine by checking if there 'type' attribute matches + // the ones included in AppConstants.possibleInputTypes). let inputDOMNode = input.getDOMNode(); - if(inputDOMNode.type && typeof inputDOMNode.type === 'string' && inputDOMNode.type.toLowerCase() && - AppConstants.possibleInputTypes.indexOf(inputDOMNode.type) > -1) { + if(inputDOMNode.type && typeof inputDOMNode.type === 'string' && + AppConstants.possibleInputTypes.indexOf(inputDOMNode.type.toLowerCase()) > -1) { inputDOMNode.value = this.state.initialValue; } @@ -118,14 +120,14 @@ let Property = React.createClass({ // // So if the input actually needs a visual reset, it needs to implement // a dedicated reset method. - if(input.reset && typeof input.reset === 'function') { + if(typeof input.reset === 'function') { input.reset(); } }, handleChange(event) { this.props.handleChange(event); - if (this.props.onChange && typeof this.props.onChange === 'function') { + if (typeof this.props.onChange === 'function') { this.props.onChange(event); } @@ -141,7 +143,7 @@ let Property = React.createClass({ // if onClick is defined from the outside, // just call it - if(this.props.onClick && typeof this.props.onClick === 'function') { + if(typeof this.props.onClick === 'function') { this.props.onClick(); } @@ -156,7 +158,7 @@ let Property = React.createClass({ isFocused: false }); - if(this.props.onBlur && typeof this.props.onBlur === 'function') { + if(typeof this.props.onBlur === 'function') { this.props.onBlur(event); } }, diff --git a/js/components/ascribe_uploader/react_s3_fine_uploader.js b/js/components/ascribe_uploader/react_s3_fine_uploader.js index 32a60e66..854b2805 100644 --- a/js/components/ascribe_uploader/react_s3_fine_uploader.js +++ b/js/components/ascribe_uploader/react_s3_fine_uploader.js @@ -603,7 +603,7 @@ var ReactS3FineUploader = React.createClass({ files = validFiles; // Call this method to signal the outside component that an upload is in progress - if(this.props.uploadStarted && typeof this.props.uploadStarted === 'function' && files.length > 0) { + if(typeof this.props.uploadStarted === 'function' && files.length > 0) { this.props.uploadStarted(); } diff --git a/js/constants/application_constants.js b/js/constants/application_constants.js index dc69e360..f1455029 100644 --- a/js/constants/application_constants.js +++ b/js/constants/application_constants.js @@ -53,6 +53,8 @@ let constants = { 'ga': 'UA-60614729-2' }, + // These are all possible types that are currently supported in HTML5 for the input element + // Source: http://www.w3schools.com/tags/att_input_type.asp 'possibleInputTypes': ['button', 'checkbox', 'color', 'date', 'datetime', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', 'url', 'week'], // in case of whitelabel customization, we store stuff here