Skip to content

Commit

Permalink
Somplify README code example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Me committed Oct 20, 2015
1 parent 02a741e commit c7b3f4a
Showing 1 changed file with 11 additions and 77 deletions.
88 changes: 11 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,22 @@ const RaisedButton = require('material-ui/lib/raised-button');

const Form = React.createClass({

childContextTypes: {
muiTheme: React.PropTypes.object
},

getChildContext(){
return {
muiTheme: Styles.ThemeManager.getMuiTheme(Styles.LightRawTheme)
}
},

getInitialState: function () {
return {
canSumbit: false
};
},

errorMessages: {
wordsError: "Please only use letters",
numericError: "Please provide a number",
urlError: "Please provide a valid URL"
wordsError: "Please only use letters"
},

selectFieldItems: [
{ payload: 'never', text: 'Never' },
{ payload: 'nightly', text: 'Every Night' },
{ payload: 'weeknights', text: 'Weeknights' },
{ payload: 'weekends', text: 'Weekends' },
{ payload: 'weekly', text: 'Weekly' }
{ payload: 'weeknights', text: 'Weeknights' }
],

styles: {
paper: {
width: 300,
margin: 20,
padding: 20
},
submit: {
marginTop: 32
}
},

enableButton: function () {
this.setState({
canSubmit: true
Expand All @@ -98,61 +73,27 @@ const Form = React.createClass({
},

submitForm: function (model) {
// Submit your validated form
console.log("Model: ", model);
alert(
`Name: ${model.name}\n
Chucked: ${model.chuck}\n
URL: ${model.url}\n
Frequency: ${model.frequency}\n
Date: ${model.date}\n
Time: ${model.time}\n
Agree: ${model.agree}\n
Toggle: ${model.toggle}\n
Speed: ${model.shipSpeed}\n
`);
},

notifyFormError: function (model) {
console.error('Form error:', model);
},

render: function () {
let styles = this.styles;
let { wordsError, numericError, urlError } = this.errorMessages;
let { wordsError } = this.errorMessages;

return (
<Paper style={styles.paper}>
<Formsy.Form
onValid={this.enableButton}
onInvalid={this.disableButton}
onValidSubmit={this.submitForm}
onInvalidSubmit={this.notifyFormError}
style={styles.form} >
onValidSubmit={this.submitForm} >

<FormsyText
<FormsyText
name='name'
validations='isWords'
validationError={wordsError}
required
hintText="What is your name?"
floatingLabelText="Name" />

<FormsyText
name='chuck'
validations='isNumeric'
validationError={numericError}
required
hintText="wood could a woodchuck chuck?"
floatingLabelText="How much" />

<FormsyText
name='url'
validations='isUrl'
validationError={urlError}
required
hintText="Where can we find out more?"
floatingLabelText="URL" />

<FormsySelect
name='frequency'
required
Expand All @@ -172,37 +113,30 @@ const Form = React.createClass({
<FormsyCheckbox
name='agree'
label="Do you agree to disagree?"
defaultChecked={true}
style={{marginBottom:16}} />
defaultChecked={true} />

<FormsyToggle
name='toggle'
label="Toggle"
style={{marginBottom:16}} />
label="Toggle" />

<FormsyRadioGroup name="shipSpeed" defaultSelected="not_light">
<FormsyRadio
value="light"
label="prepare for light speed"
style={{marginBottom:16}} />
label="prepare for light speed" />
<FormsyRadio
value="not_light"
label="light speed too slow"
style={{marginBottom:16}}/>
label="light speed too slow" />
<FormsyRadio
value="ludicrous"
label="go to ludicrous speed"
style={{marginBottom:16}}
disabled={true}/>
disabled={true} />
</FormsyRadioGroup>

<RaisedButton
style={styles.submit}
type="submit"
label="Submit"
disabled={!this.state.canSubmit} />
</Formsy.Form>
</Paper>
);
}
});
Expand Down

0 comments on commit c7b3f4a

Please sign in to comment.