Skip to content

Commit

Permalink
Add requiredError message to show onSubmit for FormsyText and FormsyS…
Browse files Browse the repository at this point in the history
…elect
  • Loading branch information
astonm committed Nov 16, 2016
1 parent d6d70b0 commit b3dbbab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/FormsySelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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 (
<SelectField
{...rest}
errorText={this.getErrorMessage()}
errorText={errorText}
onChange={this.handleChange}
ref={this.setMuiComponentAndMaybeFocus}
value={value}
Expand Down
8 changes: 6 additions & 2 deletions src/FormsyText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const FormsyText = React.createClass({
onBlur: React.PropTypes.func,
onChange: React.PropTypes.func,
onKeyDown: React.PropTypes.func,
requiredError: React.PropTypes.string,
updateImmediately: React.PropTypes.bool,
validationError: React.PropTypes.string,
validationErrors: React.PropTypes.object,
Expand Down Expand Up @@ -96,18 +97,21 @@ const FormsyText = React.createClass({
render() {
const {
defaultValue, // eslint-disable-line no-unused-vars
requiredError,
updateImmediately, // eslint-disable-line no-unused-vars
validations, // eslint-disable-line no-unused-vars
validationError, // eslint-disable-line no-unused-vars
validationErrors, // eslint-disable-line no-unused-vars
value, // eslint-disable-line no-unused-vars
...rest,
} = this.props;

const { isRequired, isPristine, isValid, isFormSubmitted } = this;
const isRequiredError = isRequired() && !isPristine() && !isValid() && isFormSubmitted() && requiredError;
const errorText = this.getErrorMessage() || isRequiredError;
return (
<TextField
{...rest}
errorText={this.getErrorMessage()}
errorText={errorText}
onBlur={this.handleBlur}
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
Expand Down

0 comments on commit b3dbbab

Please sign in to comment.