diff --git a/js/components/ascribe_forms/form.js b/js/components/ascribe_forms/form.js index f54ab06d..ab91f16d 100644 --- a/js/components/ascribe_forms/form.js +++ b/js/components/ascribe_forms/form.js @@ -109,11 +109,12 @@ let Form = React.createClass({ getFormData() { let data = {}; - for(let ref in this.refs){ + + for(let ref in this.refs) { data[this.refs[ref].props.name] = this.refs[ref].state.value; } - if (this.props.getFormData && typeof this.props.getFormData === 'function'){ + if(this.props.getFormData && typeof this.props.getFormData === 'function') { data = mergeOptionsWithDuplicates(data, this.props.getFormData()); } @@ -121,7 +122,7 @@ let Form = React.createClass({ }, handleChangeChild(){ - this.setState({edited: true}); + this.setState({ edited: true }); }, handleSuccess(response){ @@ -149,8 +150,7 @@ let Form = React.createClass({ this.setState({errors: this.state.errors.concat(err.json.errors[input])}); } } - } - else { + } else { let formData = this.getFormData(); // sentry shouldn't post the user's password diff --git a/js/components/ascribe_forms/property.js b/js/components/ascribe_forms/property.js index 61c5c96e..213c3fba 100644 --- a/js/components/ascribe_forms/property.js +++ b/js/components/ascribe_forms/property.js @@ -6,8 +6,11 @@ import ReactAddons from 'react/addons'; import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger'; import Tooltip from 'react-bootstrap/lib/Tooltip'; +import AppConstants from '../../constants/application_constants'; + import { mergeOptions } from '../../utils/general_utils'; + let Property = React.createClass({ propTypes: { hidden: React.PropTypes.bool, @@ -90,27 +93,37 @@ let Property = React.createClass({ }, reset() { + let input = this.refs.input; + // maybe do reset by reload instead of front end state? this.setState({value: this.state.initialValue}); - // resets the value of a custom react component input - this.refs.input.state.value = this.state.initialValue; + if(input.state && input.state.value) { + // resets the value of a custom react component input + input.state.value = this.state.initialValue; + } - // resets the value of a plain HTML5 input - this.refs.input.getDOMNode().value = this.state.initialValue; + // 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. + let inputDOMNode = input.getDOMNode(); + if(inputDOMNode.type && typeof inputDOMNode.type === 'string' && inputDOMNode.type.toLowerCase() && + AppConstants.possibleInputTypes.indexOf(inputDOMNode.type) > -1) { + inputDOMNode.value = this.state.initialValue; + } // For some inputs, reseting state.value is not enough to visually reset the // component. // // So if the input actually needs a visual reset, it needs to implement // a dedicated reset method. - if(this.refs.input.reset && typeof this.refs.input.reset === 'function') { - this.refs.input.reset(); + if(input.reset && typeof input.reset === 'function') { + input.reset(); } }, handleChange(event) { - this.props.handleChange(event); if (this.props.onChange && typeof this.props.onChange === 'function') { this.props.onChange(event); @@ -235,7 +248,7 @@ let Property = React.createClass({ overlay={tooltip}>