Comparing version 0.0.5 to 0.0.6
@@ -172,3 +172,3 @@ 'use strict'; | ||
return _react2.default.createElement(Component, _extends({}, props, { | ||
className: 'form-control ' + className, | ||
className: 'form-control ' + (className || ''), | ||
onCompositionStart: this.handleComposition, | ||
@@ -175,0 +175,0 @@ onCompositionUpdate: this.handleComposition, |
@@ -39,2 +39,4 @@ 'use strict'; | ||
name: _propTypes2.default.string.isRequired, | ||
onChange: _propTypes2.default.func, | ||
onBlur: _propTypes2.default.func, | ||
accepter: _elementType2.default | ||
@@ -59,6 +61,2 @@ }; | ||
if (!props.name) { | ||
throw new Error(' `name` is undefined on <Field>'); | ||
} | ||
var _context$form = context.form, | ||
@@ -84,4 +82,6 @@ _context$form$values = _context$form.values, | ||
key: 'handleFieldChange', | ||
value: function handleFieldChange(value) { | ||
var name = this.props.name; | ||
value: function handleFieldChange(value, event) { | ||
var _props = this.props, | ||
name = _props.name, | ||
onChange = _props.onChange; | ||
var _context$form2 = this.context.form, | ||
@@ -94,10 +94,13 @@ onFieldChange = _context$form2.onFieldChange, | ||
this.setState({ checkResult: checkResult, value: value }); | ||
onFieldChange(name, value, checkResult); | ||
onFieldChange(name, value, checkResult, event); | ||
onChange && onChange(value, event); | ||
} | ||
}, { | ||
key: 'handleFieldBlur', | ||
value: function handleFieldBlur() { | ||
value: function handleFieldBlur(event) { | ||
var onBlur = this.props.onBlur; | ||
var checkTrigger = this.context.form.checkTrigger; | ||
this.handleFieldCheck(this.state.value, checkTrigger === 'blur'); | ||
onBlur && onBlur(event); | ||
} | ||
@@ -129,6 +132,6 @@ }, { | ||
value: function render() { | ||
var _props = this.props, | ||
name = _props.name, | ||
Component = _props.accepter, | ||
props = _objectWithoutProperties(_props, ['name', 'accepter']); | ||
var _props2 = this.props, | ||
name = _props2.name, | ||
Component = _props2.accepter, | ||
props = _objectWithoutProperties(_props2, ['name', 'accepter']); | ||
@@ -140,10 +143,8 @@ var _context$form4 = this.context.form, | ||
defaultValues = _context$form4$defaul === undefined ? {} : _context$form4$defaul; | ||
var checkResult = this.state.checkResult; | ||
return _react2.default.createElement(Component, _extends({}, props, { | ||
name: name, | ||
onChange: this.handleFieldChange, | ||
onBlur: this.handleFieldBlur, | ||
errorMessage: checkResult.errorMessage, | ||
isValid: checkResult.hasError === undefined ? undefined : !checkResult.hasError, | ||
defaultValue: defaultValues[name], | ||
@@ -150,0 +151,0 @@ value: values[name] |
@@ -7,2 +7,4 @@ 'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -30,2 +32,4 @@ | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -228,5 +232,4 @@ | ||
className = _props5.className, | ||
children = _props5.children; | ||
props = _objectWithoutProperties(_props5, ['horizontal', 'inline', 'className']); | ||
var clesses = (0, _classnames2.default)('form', { | ||
@@ -237,12 +240,10 @@ 'form-horizontal': horizontal, | ||
return _react2.default.createElement( | ||
'form', | ||
{ | ||
onSubmit: function onSubmit(e) { | ||
e.preventDefault(); | ||
}, | ||
className: clesses | ||
var elementProps = _lodash2.default.omit(props, Object.keys(propTypes)); | ||
return _react2.default.createElement('form', _extends({}, elementProps, { | ||
onSubmit: function onSubmit(e) { | ||
e.preventDefault(); | ||
}, | ||
children | ||
); | ||
className: clesses | ||
})); | ||
} | ||
@@ -249,0 +250,0 @@ }]); |
{ | ||
"name": "form-lib", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Form component for React", | ||
@@ -52,2 +52,3 @@ "main": "lib/index.js", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"chai": "^4.1.0", | ||
"css-loader": "^0.23.1", | ||
@@ -70,6 +71,8 @@ "eslint": "^3.19.0", | ||
"karma-coverage": "^1.1.0", | ||
"karma-firefox-launcher": "^1.0.0", | ||
"karma-mocha": "^1.1.1", | ||
"karma-mocha-reporter": "^2.0.4", | ||
"karma-sinon-chai": "^1.2.2", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
"karma-webpack": "^1.7.0", | ||
"karma-webpack": "2.0.3", | ||
"less": "^2.7.1", | ||
@@ -83,3 +86,3 @@ "less-loader": "^2.2.3", | ||
"react-hot-loader": "^3.0.0-beta.6", | ||
"rsuite": "1.0.11", | ||
"rsuite": "^1.0.14", | ||
"rsuite-affix": "^1.0.3", | ||
@@ -89,2 +92,4 @@ "rsuite-picker": "^0.3.3", | ||
"rsuite-theme": "^0.3.35", | ||
"sinon": "^1.17.4", | ||
"sinon-chai": "^2.8.0", | ||
"style-loader": "^0.17.0", | ||
@@ -91,0 +96,0 @@ "url-loader": "^0.5.7", |
31558
572
52