1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
3 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
4 | import _inherits from 'babel-runtime/helpers/inherits';
|
5 |
|
6 | var _class, _temp2;
|
7 |
|
8 | import React from 'react';
|
9 | import PropTypes from 'prop-types';
|
10 | import Button from '../button';
|
11 | import { func, obj } from '../util';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var Submit = (_temp2 = _class = function (_React$Component) {
|
19 | _inherits(Submit, _React$Component);
|
20 |
|
21 | function Submit() {
|
22 | var _temp, _this, _ret;
|
23 |
|
24 | _classCallCheck(this, Submit);
|
25 |
|
26 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
27 | args[_key] = arguments[_key];
|
28 | }
|
29 |
|
30 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.handleClick = function () {
|
31 | var _this$props = _this.props,
|
32 | onClick = _this$props.onClick,
|
33 | validate = _this$props.validate;
|
34 |
|
35 | var field = _this.context._formField || _this.props.field;
|
36 |
|
37 | if (!field) {
|
38 | onClick();
|
39 | return;
|
40 | }
|
41 |
|
42 | if (validate === true) {
|
43 | field.validate(function (errors) {
|
44 | onClick(field.getValues(), errors, field);
|
45 | });
|
46 | } else if (Array.isArray(validate)) {
|
47 | field.validate(validate, function (errors) {
|
48 | onClick(field.getValues(), errors, field);
|
49 | });
|
50 | } else {
|
51 | onClick(field.getValues(), null, field);
|
52 | }
|
53 | }, _temp), _possibleConstructorReturn(_this, _ret);
|
54 | }
|
55 |
|
56 | Submit.prototype.render = function render() {
|
57 | var children = this.props.children;
|
58 |
|
59 |
|
60 | return React.createElement(
|
61 | Button,
|
62 | _extends({}, obj.pickOthers(Submit.propTypes, this.props), {
|
63 | onClick: this.handleClick
|
64 | }),
|
65 | children
|
66 | );
|
67 | };
|
68 |
|
69 | return Submit;
|
70 | }(React.Component), _class.propTypes = {
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | onClick: PropTypes.func,
|
78 | |
79 |
|
80 |
|
81 | validate: PropTypes.oneOfType([PropTypes.bool, PropTypes.array]),
|
82 | |
83 |
|
84 |
|
85 | field: PropTypes.object,
|
86 | children: PropTypes.node
|
87 | }, _class.defaultProps = {
|
88 | onClick: func.noop
|
89 | }, _class.contextTypes = {
|
90 | _formField: PropTypes.object
|
91 | }, _temp2);
|
92 | Submit.displayName = 'Submit';
|
93 |
|
94 |
|
95 | export default Submit; |
\ | No newline at end of file |