Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Textfield dafault value #23

Merged
merged 3 commits into from
Nov 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
118 changes: 61 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: For React 0.13.x compatibility, specify formsy-react 0.14.1 in your app.

## Usage

Note for `FormsyText` you must use `value` instead of `defaultValue` to set a default value.

### ES6:

```js
Expand Down Expand Up @@ -81,62 +83,63 @@ const Form = React.createClass({
let { wordsError } = this.errorMessages;

return (
<Formsy.Form
onValid={this.enableButton}
onInvalid={this.disableButton}
onValidSubmit={this.submitForm} >

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

<FormsySelect
name='frequency'
required
floatingLabelText="How often do you?"
menuItems={this.selectFieldItems}/>

<FormsyDate
name='date'
required
floatingLabelText="Date" />

<FormsyTime
name='time'
required
floatingLabelText="Time" />

<FormsyCheckbox
name='agree'
label="Do you agree to disagree?"
defaultChecked={true} />

<FormsyToggle
name='toggle'
label="Toggle" />

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

<RaisedButton
type="submit"
label="Submit"
disabled={!this.state.canSubmit} />
</Formsy.Form>
<Formsy.Form
onValid={this.enableButton}
onInvalid={this.disableButton}
onValidSubmit={this.submitForm} >

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

<FormsySelect
name='frequency'
required
floatingLabelText="How often do you?"
menuItems={this.selectFieldItems}/>

<FormsyDate
name='date'
required
floatingLabelText="Date" />

<FormsyTime
name='time'
required
floatingLabelText="Time" />

<FormsyCheckbox
name='agree'
label="Do you agree to disagree?"
defaultChecked={true} />

<FormsyToggle
name='toggle'
label="Toggle" />

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

<RaisedButton
type="submit"
label="Submit"
disabled={!this.state.canSubmit} />
</Formsy.Form>
);
}
});
Expand All @@ -159,7 +162,8 @@ See [issues](https://github.com/mbrookes/formsy-material-ui/issues).
* 0.2.1 Convert dependencies to peerDependencies.
* 0.2.2 Add prepublish script and associated dev dependency to package.json.
* 0.2.3 Fix textfield initialization through this.refs.form.reset(model) (@vijayrawatsan).
* 0.2.4 Updated textfield handling (@vijayrawatsan), selectfield fix (@dmlinn),
* 0.2.4 Updated textfield handling (@vijayrawatsan), selectfield fix (@dmlinn).
* 0.2.5 (Unpublished). Fix issue #21 defaults?

## Acknowledgements

Expand Down
5 changes: 1 addition & 4 deletions formsy-material-ui.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ let FormsyText = React.createClass({
}
},

handleValueChange: function handleValueChange(event, value) {
this.setValue(value);
},

handleBlur: function handleBlur(event) {
this.setValue(event.currentTarget.value);
},
Expand All @@ -145,6 +141,7 @@ let FormsyText = React.createClass({
return (
<TextField
{...this.props}
defaultValue={this.props.value}
onChange={this.handleChange}
onBlur={this.handleBlur}
onEnterKeyDown={this.handleEnterKeyDown}
Expand Down
7 changes: 2 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ var FormsyText = React.createClass({
}
},

handleValueChange: function handleValueChange(event, value) {
this.setValue(value);
},

handleBlur: function handleBlur(event) {
this.setValue(event.currentTarget.value);
},
Expand All @@ -154,6 +150,7 @@ var FormsyText = React.createClass({

render: function render() {
return React.createElement(TextField, _extends({}, this.props, {
defaultValue: this.props.value,
onChange: this.handleChange,
onBlur: this.handleBlur,
onEnterKeyDown: this.handleEnterKeyDown,
Expand Down Expand Up @@ -202,4 +199,4 @@ module.exports = {
FormsyText: FormsyText,
FormsyTime: FormsyTime,
FormsyToggle: FormsyToggle
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formsy-material-ui",
"version": "0.2.4",
"version": "0.2.5",
"description": "A formsy-react compatibility wrapper for Material-UI form components.",
"main": "index.js",
"scripts": {
Expand Down
163 changes: 163 additions & 0 deletions test/TextfieldTests.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
injectTapEventPlugin();

let { FormsyText } = FMUI;

TestForm = React.createClass({

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

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

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

styles: {
paperStyle: {
width: 300,
margin: 20,
padding: 20
},
submitStyle: {
marginTop: 32
},
spanStyle: {
marginTop: 32,
fontSize: 10,
fontColor: "grey"
}
},

enableButton: function () {
this.setState({
canSubmit: true
});
},

disableButton: function () {
this.setState({
canSubmit: false
});
},

submitForm: function (data) {
alert(JSON.stringify(data, null, 4));
},

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

render: function () {
const {paperStyle, submitStyle, spanStyle } = this.styles;
const wordsError = "Please only use letters";

return (
<Paper style={paperStyle}>

<Formsy.Form
onValid={this.enableButton}
onInvalid={this.disableButton}
onValidSubmit={this.submitForm}
onInvalidSubmit={this.notifyFormError} >

<span style={spanStyle}>Name only - all following have a name and some other combination of options.</span>
<FormsyText
name='name' />

<span style={spanStyle}>floatingLabelText</span>
<FormsyText
name='label'
floatingLabelText="Name" />

<span style={spanStyle}>hintText</span>
<FormsyText
name='hint'
hintText="Hint text"
/>

<span style={spanStyle}>floatingLabelText, hintText</span>
<FormsyText
name='label-hint'
floatingLabelText="Name"
hintText="Hint text"
/>

<span style={spanStyle}>floatingLabelText, defaultValue</span>
<FormsyText
name='label-default'
floatingLabelText="Name"
defaultValue="default"
/>

<span style={spanStyle}>hintText, defaultValue</span>
<FormsyText
name='hint-default'
hintText="Hint text"
defaultValue="default"
/>

<span style={spanStyle}>floatingLabelText, hintText, defaultValue</span>
<FormsyText
name='label-hint-default'
floatingLabelText="Name"
hintText="Hint text"
defaultValue="default"
/>

<span style={spanStyle}>required</span>
<FormsyText
name='required'
required />

<span style={spanStyle}>validation</span>
<FormsyText
name='validation'
validations='isWords' />

<span style={spanStyle}>validation, validationError</span>
<FormsyText
name='validation-error'
validations='isWords'
validationError={wordsError} />

<span style={spanStyle}>validation, required</span>
<FormsyText
name='validation-required'
validations='isWords'
required />

<span style={spanStyle}>validation, validationError, required</span>
<FormsyText
name='validation-error-required'
validations='isWords'
validationError={wordsError}
required />

<span style={spanStyle}>validation, validationError, required, hintText, label</span>
<FormsyText
name='validation-error-required-hint-label'
validations='isWords'
validationError={wordsError}
required
hintText="What is your name?"
floatingLabelText="Name" />

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