This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { Field, reduxForm } from 'redux-form'; | |
| function validate(values) { | |
| const errors = {} | |
| if (!values.firstName) { | |
| errors.firstName = 'Required' | |
| } | |
| if (!values.lastName) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div> | |
| <label>First Name</label> | |
| <div> | |
| <Field | |
| name="firstName" | |
| component={renderField} | |
| type="text" | |
| placeholder="First Name" | |
| /> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const renderField = ({ | |
| input, | |
| type, | |
| meta: { touched, error } | |
| }) => ( | |
| <div> | |
| <label>{label}</label> | |
| <div> | |
| <input {...input} placeholder={label} type={type} /> | |
| {touched && error && <span>{error}</span>} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function validate(values) { | |
| const errors = {} | |
| if (!values.firstName) { | |
| errors.firstName = 'Required' | |
| } | |
| return errors | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div> | |
| <label>First Name</label> | |
| <div> | |
| <Field | |
| name="firstName" | |
| component="input" | |
| type="text" | |
| placeholder="First Name" | |
| /> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); | |
| export default (async function showResults(values) { | |
| await sleep(500); | |
| window.alert(`You submitted:\n\n${JSON.stringify(values, null, 2)}`); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import { Provider } from "react-redux"; | |
| import store from "./store"; | |
| import showResults from "./showResults"; | |
| import SimpleForm from "./SimpleForm"; | |
| class App extends Component { | |
| render() { | |
| return ( | |
| <Provider store={store}> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { Field, reduxForm } from 'redux-form'; | |
| const SimpleForm = props => { | |
| const { handleSubmit, pristine, reset, submitting } = props; | |
| return ( | |
| <form onSubmit={handleSubmit}> | |
| <div> | |
| <label>First Name</label> | |
| <div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createStore, combineReducers } from 'redux'; | |
| import { reducer as reduxFormReducer } from 'redux-form'; | |
| const reducer = combineReducers({ | |
| form: reduxFormReducer, | |
| }); | |
| const store = (window.devToolsExtension | |
| ? window.devToolsExtension()(createStore) | |
| : createStore)(reducer); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Ruby's String#center, String#rjust, String#ljust | |
| * | |
| * https://jsfiddle.net/6v0bpffm/ | |
| */ | |
| function ljust( string, width, padding ) { | |
| padding = padding || " "; | |
| padding = padding.substr( 0, 1 ); | |
| if ( string.length < width ) |
NewerOlder