Comparing version 0.10.0 to 0.10.1
@@ -47,3 +47,3 @@ 'use strict'; | ||
fieldValue: fieldValue, | ||
errorMessage: _this.validate(fieldValue), | ||
errorMessage: _this.validate(fieldValue, props), | ||
dirty: false | ||
@@ -162,6 +162,6 @@ }; | ||
this.validate = function (fieldValue) { | ||
var _props2 = _this2.props, | ||
validation = _props2.validation, | ||
required = _props2.required, | ||
type = _props2.type; | ||
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this2.props; | ||
var validation = props.validation, | ||
required = props.required, | ||
type = props.type; | ||
@@ -185,3 +185,3 @@ var errorMessage = ''; | ||
errorMessage = validation.map(function (fun) { | ||
return fun(fieldValue, _this2.props.name); | ||
return fun(fieldValue, props.label || props.name); | ||
}).filter(function (m) { | ||
@@ -188,0 +188,0 @@ return m; |
{ | ||
"name": "formact", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"description": "A React Set of Form Components with Context", | ||
@@ -11,3 +11,4 @@ "main": "lib/index.js", | ||
"build:types": "cp ./lib/types.js.flow ./types.js", | ||
"build": "npm run build:clean && npm run build:compile && npm run build:flow && npm run build:types", | ||
"build": | ||
"yarn build:clean && yarn build:compile && yarn build:flow && yarn build:types", | ||
"flow": "yarn build && flow", | ||
@@ -17,4 +18,4 @@ "lint": "eslint ./src", | ||
"coverage": "jest --coverage", | ||
"test": "npm run lint && npm run flow && npm run jest", | ||
"start": "npm test && npm run build", | ||
"test": "yarn lint && yarn flow && yarn jest", | ||
"start": "npm test && yarn build", | ||
"prepublishOnly": "npm start" | ||
@@ -51,6 +52,6 @@ }, | ||
"eslint-plugin-react": "^7.1.0", | ||
"flow-bin": "^0.49.1", | ||
"flow-bin": "^0.55.0", | ||
"flow-copy-source": "^1.2.0", | ||
"jest": "^20.0.4", | ||
"prettier": "^1.5.2", | ||
"prettier": "^1.7.2", | ||
"react": "^15.6.1", | ||
@@ -57,0 +58,0 @@ "react-dom": "^15.6.1", |
@@ -17,3 +17,3 @@ // @flow | ||
{...props} | ||
render={routeComponentProps => | ||
render={routeComponentProps => ( | ||
<Component | ||
@@ -23,3 +23,4 @@ {...remainingProps} | ||
ref={wrappedComponentRef} | ||
/>} | ||
/> | ||
)} | ||
/> | ||
@@ -26,0 +27,0 @@ ) |
@@ -15,9 +15,13 @@ // @flow | ||
export default class Form extends Component { | ||
props: { | ||
onSubmit: (e: SyntheticEvent, payload: FormSubmitPayload) => void, | ||
onChange?: (payload: FormChangePayload) => void, | ||
children: ElementChildren, | ||
} | ||
type Props = { | ||
onSubmit: (e: SyntheticEvent<*>, payload: FormSubmitPayload) => void, | ||
onChange?: (payload: FormChangePayload) => void, | ||
children: ElementChildren, | ||
} | ||
type State = { | ||
submitted: boolean, | ||
} | ||
export default class Form extends Component<Props, State> { | ||
static childContextTypes = { | ||
@@ -30,5 +34,3 @@ addField: PropTypes.func, | ||
state: { | ||
submitted: boolean, | ||
} = { | ||
state = { | ||
submitted: false, | ||
@@ -120,3 +122,3 @@ } | ||
onSubmit = (e: SyntheticEvent) => { | ||
onSubmit = (e: SyntheticEvent<*>) => { | ||
const valid = this.isValid() | ||
@@ -140,3 +142,3 @@ this.setState({ | ||
onChange(e: SyntheticEvent) { | ||
onChange(e: SyntheticEvent<*>) { | ||
e.preventDefault() | ||
@@ -143,0 +145,0 @@ } |
@@ -12,2 +12,3 @@ // @flow | ||
name: FieldName, | ||
label?: ?string, | ||
required?: ?boolean, | ||
@@ -23,5 +24,9 @@ fieldValue?: ?FieldValue, | ||
export default class FormactMe extends Component { | ||
props: Props | ||
type State = { | ||
fieldValue: ?FieldValue, | ||
errorMessage: ?string, | ||
dirty: boolean, | ||
} | ||
export default class FormactMe extends Component<Props, State> { | ||
static contextTypes = { | ||
@@ -34,8 +39,2 @@ addField: PropTypes.func, | ||
state: { | ||
fieldValue: ?FieldValue, | ||
errorMessage: ?string, | ||
dirty: boolean, | ||
} | ||
constructor(props: Props, context: any) { | ||
@@ -48,3 +47,3 @@ super(props, context) | ||
fieldValue, | ||
errorMessage: this.validate(fieldValue), | ||
errorMessage: this.validate(fieldValue, props), | ||
dirty: false, | ||
@@ -120,4 +119,4 @@ } | ||
validate = (fieldValue: ?FieldValue) => { | ||
let { validation, required, type } = this.props | ||
validate = (fieldValue: ?FieldValue, props: Props = this.props) => { | ||
let { validation, required, type } = props | ||
let errorMessage = '' | ||
@@ -140,3 +139,3 @@ | ||
errorMessage = validation | ||
.map(fun => fun(fieldValue, this.props.name)) | ||
.map(fun => fun(fieldValue, props.label || props.name)) | ||
.filter(m => m) | ||
@@ -143,0 +142,0 @@ .join(' ') |
@@ -18,9 +18,11 @@ // @flow | ||
defaultValue?: string, | ||
onChange?: (e: SyntheticEvent) => void, | ||
onChange?: (e: SyntheticEvent<*>) => void, | ||
validation?: FieldValidateFunction | Array<FieldValidateFunction>, | ||
} | ||
export default class Input extends Component { | ||
props: Props | ||
type State = { | ||
value: string, | ||
} | ||
export default class Input extends Component<Props, State> { | ||
static defaultProps = { | ||
@@ -37,6 +39,2 @@ type: 'text', | ||
state: { | ||
value: string, | ||
} | ||
constructor(props: Props, context: any) { | ||
@@ -103,3 +101,3 @@ super(props, context) | ||
onChange = (e: SyntheticEvent) => { | ||
onChange = (e: SyntheticEvent<*>) => { | ||
const { value } = (e.currentTarget: window.HTMLInputElement) | ||
@@ -106,0 +104,0 @@ |
@@ -15,3 +15,3 @@ // @flow | ||
defaultValue?: string, | ||
onChange?: (e: SyntheticEvent) => void, | ||
onChange?: (e: SyntheticEvent<*>) => void, | ||
options: Array<string | Object>, | ||
@@ -21,5 +21,7 @@ validation?: FieldValidateFunction | Array<FieldValidateFunction>, | ||
export default class Select extends Component { | ||
props: Props | ||
type State = { | ||
value: string, | ||
} | ||
export default class Select extends Component<Props, State> { | ||
static contextTypes = { | ||
@@ -32,6 +34,2 @@ addField: PropTypes.func, | ||
state: { | ||
value: string, | ||
} | ||
constructor(props: Props, context: any) { | ||
@@ -111,3 +109,3 @@ super(props, context) | ||
onChange = (e: SyntheticEvent) => { | ||
onChange = (e: SyntheticEvent<*>) => { | ||
const { value } = (e.currentTarget: window.HTMLInputElement) | ||
@@ -151,7 +149,3 @@ | ||
if (typeof item === 'string') { | ||
return ( | ||
<option key={`option-${item}`}> | ||
{item} | ||
</option> | ||
) | ||
return <option key={`option-${item}`}>{item}</option> | ||
} | ||
@@ -158,0 +152,0 @@ return <option {...item} key={`option-${item.toString()}`} /> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
215456
1316