diff --git a/.gitignore b/.gitignore index 491fc359..a83f1f80 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules lib +.idea/ +.DS_Store \ No newline at end of file diff --git a/examples/components/Input.js b/examples/components/Input.js index fd668344..a8730709 100644 --- a/examples/components/Input.js +++ b/examples/components/Input.js @@ -32,7 +32,8 @@ const MyInput = React.createClass({ type={this.props.type || 'text'} name={this.props.name} onChange={this.changeValue} - value={this.getValue()} + value={this.getValue() || ''} + placeholder={this.props.placeholder && this.props.type !== 'checkbox' ? this.props.placeholder : ''} checked={this.props.type === 'checkbox' && this.getValue() ? 'checked' : null} /> {errorMessage} diff --git a/examples/components/Select.js b/examples/components/Select.js index cf619be7..c9dbafc2 100644 --- a/examples/components/Select.js +++ b/examples/components/Select.js @@ -22,7 +22,7 @@ const MySelect = React.createClass({ return (
- {options} {errorMessage} diff --git a/examples/components/Textarea.js b/examples/components/Textarea.js new file mode 100644 index 00000000..32beadf8 --- /dev/null +++ b/examples/components/Textarea.js @@ -0,0 +1,47 @@ +/** + * Created by iamraphson on 9/24/16. + */ +import React from 'react'; +import Formsy from 'formsy-react'; + +const MyTextarea = React.createClass({ + + // Add the Formsy Mixin + mixins: [Formsy.Mixin], + + // setValue() will set the value of the component, which in + // turn will validate it and the rest of the form + changeValue(event) { + this.setValue(event.currentTarget.value); + }, + render() { + + // Set a specific className based on the validation + // state of this component. showRequired() is true + // when the value is empty and the required prop is + // passed to the input. showError() is true when the + // value typed is invalid + const className = 'form-group' + (this.props.className || ' ') + + (this.showRequired() ? ' required' : this.showError() ? ' error' : ''); + + // An error message is returned ONLY if the component is invalid + // or the server has returned an error message + const errorMessage = this.getErrorMessage(); + + return ( +
+ +