From 69d990a0af1a1beb6f6649617f8cb961b10c1aaa Mon Sep 17 00:00:00 2001 From: Ayeni Olusegun Date: Sat, 24 Sep 2016 06:31:14 +0100 Subject: [PATCH 1/2] worked on the textarea component and added placeholder in the input component --- .gitignore | 2 ++ examples/components/Input.js | 1 + examples/components/Textarea.js | 48 +++++++++++++++++++++++++++++++++ examples/global.css | 12 ++++++--- examples/reset-values/app.js | 7 +++-- 5 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 examples/components/Textarea.js 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..95485144 100644 --- a/examples/components/Input.js +++ b/examples/components/Input.js @@ -33,6 +33,7 @@ const MyInput = React.createClass({ name={this.props.name} onChange={this.changeValue} 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/Textarea.js b/examples/components/Textarea.js new file mode 100644 index 00000000..37d9ef9b --- /dev/null +++ b/examples/components/Textarea.js @@ -0,0 +1,48 @@ +/** + * 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 ( +
+ +