From b3dbbabf1c331227b650e434ae41aade8a97796f Mon Sep 17 00:00:00 2001 From: Aston Motes Date: Tue, 15 Nov 2016 16:19:00 -0800 Subject: [PATCH] Add requiredError message to show onSubmit for FormsyText and FormsySelect --- src/FormsySelect.jsx | 18 ++++++++++++------ src/FormsyText.jsx | 8 ++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/FormsySelect.jsx b/src/FormsySelect.jsx index e90ed8e..8e1ffa7 100644 --- a/src/FormsySelect.jsx +++ b/src/FormsySelect.jsx @@ -9,6 +9,7 @@ const FormsySelect = React.createClass({ children: React.PropTypes.node, name: React.PropTypes.string.isRequired, onChange: React.PropTypes.func, + requiredError: React.PropTypes.string, validationError: React.PropTypes.string, validationErrors: React.PropTypes.object, validations: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.object]), @@ -38,17 +39,22 @@ const FormsySelect = React.createClass({ render() { let { value } = this.props; - const { validations, // eslint-disable-line no-unused-vars - validationError, // eslint-disable-line no-unused-vars - validationErrors, // eslint-disable-line no-unused-vars - ...rest } = this.props; + const { + requiredError, + validations, // eslint-disable-line no-unused-vars + validationError, // eslint-disable-line no-unused-vars + validationErrors, // eslint-disable-line no-unused-vars + ...rest + } = this.props; value = this.state.hasChanged ? this.getValue() : value; - + const { isRequired, isPristine, isValid, isFormSubmitted } = this; + const isRequiredError = isRequired() && !isPristine() && !isValid() && isFormSubmitted() && requiredError; + const errorText = this.getErrorMessage() || isRequiredError; return (