-
Notifications
You must be signed in to change notification settings - Fork 1
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
Development for 2.0 #17
Changes from all commits
91ffc58
01c6dee
b3a3814
638217b
de68c9f
bbd7a3d
65cc259
3554918
6b9755f
dbbbd9d
1d003a9
0ca087d
b97f373
4c48c52
e7751b3
6b7ce59
ea3709d
6b7dae7
65437e1
85ca657
69801ed
3754a9f
2b750a4
f1486de
991ffc4
bba24d5
c2c5c8b
cb34be9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"lerna": "2.0.0", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"npmClient": "yarn", | ||
"packages": [ | ||
"packages/*" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "react-form-utils", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Serialize/Deserialize form input, and lookup", | ||
"main": "build/index.js", | ||
"author": "[email protected]", | ||
|
@@ -21,7 +21,7 @@ | |
}, | ||
"homepage": "https://github.com/blacktangent/react-layout-builder", | ||
"dependencies": { | ||
"form-serialize": "alvinsj/form-serialize#export-fn", | ||
"@alvinsj/form-serialize": "^0.7.2-alpha.1", | ||
"object-assign": "^4.x.x" | ||
}, | ||
"scripts": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "react-form-with-layout", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "A helper to build form layout", | ||
"main": "build/index.js", | ||
"author": "[email protected]", | ||
|
@@ -24,8 +24,8 @@ | |
"classnames": "^2.1.3", | ||
"object-assign": "^4.0.1", | ||
"object.assign": "^4.0.4", | ||
"react-form-utils": "^1.2.0", | ||
"react-layout-builder": "^1.2.0" | ||
"react-form-utils": "^2.0.0", | ||
"react-layout-builder": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel": "^6.5.x", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,7 @@ export default class FormWithLayout extends React.Component { | |
'props.renderLayout and props.renderField is required.' | ||
); | ||
|
||
this._isMounted = false; | ||
|
||
this.renderField = this.renderField.bind(this); | ||
this.fields = {}; | ||
} | ||
|
||
componentDidMount() { | ||
this._isMounted = true; | ||
} | ||
|
||
render() { | ||
|
@@ -44,48 +37,57 @@ export default class FormWithLayout extends React.Component { | |
: props.renderLayout(formBuilder, props); | ||
|
||
return ( | ||
<form {...formProps} className={props.className || 'form-horizontal'}> | ||
<form | ||
ref={c => (this.form = c)} | ||
{...formProps} | ||
className={props.className || 'form-horizontal'} | ||
> | ||
{children} | ||
{props.renderButtons ? props.renderButtons(props) : <div />} | ||
</form> | ||
); | ||
} | ||
|
||
renderField(name) { | ||
const props = this.props; | ||
|
||
const value = inputValueLookup(props.values || {}, name); | ||
const error = props.errors ? props.errors[name] : null; | ||
const def = props.getFieldProps(name); | ||
|
||
// form.defaultValues(field).defaultValue | ||
var defaultValue = inputValueLookup(props.defaultValues || {}, name); | ||
|
||
// fieldProps.value > form.defaultValues(field).defaultValue | ||
defaultValue = | ||
def.defaultValue === null || typeof def.defaultValue === 'undefined' | ||
? defaultValue | ||
: def.defaultValue; | ||
|
||
// form.props.disabled > fieldProps.disabled | ||
var disabled = props.disabled || def.disabled; | ||
|
||
var label = def.label ? def.label : humanize(name); | ||
|
||
const fieldProps = assign({}, def, { | ||
className: 'field', | ||
field: def, | ||
const formProps = this.props; | ||
const fieldProps = formProps.getFieldProps(name); | ||
|
||
const label = | ||
typeof fieldProps.label !== 'undefined' | ||
? fieldProps.label | ||
: humanize(name); | ||
|
||
// fieldProps.disabled > formProps.disabled > | ||
const disabled = | ||
typeof fieldProps.disabled !== 'undefined' | ||
? fieldProps.disabled | ||
: formProps.disabled; | ||
|
||
// fieldProps.defaultValue > formProps.defaultValues(field).defaultValue | ||
const defaultValue = | ||
typeof fieldProps.defaultValue !== 'undefined' | ||
? fieldProps.defaultValue | ||
: inputValueLookup(formProps.defaultValues || {}, name); | ||
|
||
// fieldProps.value > formProps.values(field).value | ||
const value = | ||
typeof fieldProps.value !== 'undefined' | ||
? fieldProps.value | ||
: inputValueLookup(formProps.values || {}, name); | ||
|
||
const inputProps = assign({}, fieldProps, { | ||
name: name, | ||
value: value, | ||
defaultValue: defaultValue, | ||
label: label, | ||
error: error, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
disabled: disabled | ||
disabled: disabled, | ||
|
||
defaultValue: typeof value !== 'undefined' ? undefined : defaultValue, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if there is related issue: #21 |
||
formProps: formProps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a new key: related issue: #20 |
||
}); | ||
|
||
return def.input | ||
? React.createElement(def.input, fieldProps) | ||
: props.renderField(name, fieldProps); | ||
return fieldProps.input | ||
? React.createElement(fieldProps.input, inputProps) | ||
: formProps.renderField(name, inputProps); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "react-layout-builder", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Build form layout", | ||
"main": "build/index.js", | ||
"author": "[email protected]", | ||
|
@@ -25,7 +25,7 @@ | |
}, | ||
"dependencies": { | ||
"object-assign": "^4.x.x", | ||
"react-form-utils": "^1.2.0" | ||
"react-form-utils": "^2.0.0" | ||
}, | ||
"scripts": { | ||
"jest": "NODE_PATH=src:NODE_PATH jest", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import React from 'react'; | ||
|
||
var layoutCount = 0; | ||
export const layout = (...children) => { | ||
return ( | ||
<div key={`layout-${layoutCount++}`} className="layout"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<div className="layout"> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
var sectionCount = 0; | ||
export const section = (name, ...rows) => { | ||
export const section = (key, name, ...rows) => { | ||
const renderedRows = rows.map((cols, index) => { | ||
return ( | ||
<div key={`columns-${index}`} className="columns"> | ||
|
@@ -19,7 +17,7 @@ export const section = (name, ...rows) => { | |
); | ||
}); | ||
return ( | ||
<div key={`section-${sectionCount++}`} className="section"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<div key={key} className="section"> | ||
{name && name !== '' | ||
? <h5> | ||
{name} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the returned value should be fixed to
undefined
when it's not found. (related issue #18)