UNPKG

cosmo-ui

Version:
69 lines 3.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var react_redux_1 = require("react-redux"); var _1 = require("."); var reducers_1 = require("../reducers"); var data_1 = require("../data"); var selectors_1 = require("../selectors"); var actions_1 = require("../actions"); var styles = require('../../src/styles/components/forms.scss'); var _AddressInput = (function (_super) { tslib_1.__extends(_AddressInput, _super); function _AddressInput() { return _super !== null && _super.apply(this, arguments) || this; } // TODO - implement the async stuff // renderSpinner(): JSX.Element { // return <Spinner visible={this.props.field.loading} /> // } _AddressInput.prototype.renderField = function () { var _a = this.props, name = _a.name, disabled = _a.disabled, placeholder = _a.placeholder; // console.log('render text input', this.props) return (React.createElement("input", { ref: this.setFieldRef, className: this.classNames(), name: name, id: name + "Field", placeholder: placeholder, type: "text", value: this.parseAsyncValue(), disabled: disabled, onChange: this.onChange, onFocus: this.onFocus, onBlur: this.onBlur })); }; _AddressInput.prototype.validate = function () { var asyncValue = this.props.field.asyncValue; if (!asyncValue || !asyncValue.address) { return ['* required']; } if (!asyncValue.address.postcode) { return ['* valid UK post code required']; } if (!asyncValue.address.town) { return ['* valid UK city required']; } return []; }; _AddressInput.prototype.parseAsyncValue = function () { var asyncValue = this.props.field.asyncValue; // console.log('PARSING ADDRESS VALUE', asyncValue ) if (asyncValue) { return [ asyncValue.address.streets.join(', '), asyncValue.address.postcode, ].join(', '); } return this.getValueFromState(); }; return _AddressInput; }(_1.BaseFormField)); var mapStateToProps = function (state, ownProps) { return (tslib_1.__assign({}, ownProps, { field: selectors_1.mapStateToField(state[reducers_1.FORM_REDUCER_KEY], ownProps, data_1.createAsyncFormField) })); }; var mapDispatchToProps = { setFormField: actions_1.setFormField, asyncOnChange: actions_1.searchAddress, }; var ConnectedAddressInput = react_redux_1.connect(mapStateToProps, mapDispatchToProps)(_AddressInput); var AddressInput = (function (_super) { tslib_1.__extends(AddressInput, _super); function AddressInput() { return _super !== null && _super.apply(this, arguments) || this; } AddressInput.prototype.render = function () { return (React.createElement(ConnectedAddressInput, tslib_1.__assign({}, this.props, { formName: this.formName }))); }; return AddressInput; }(_1.FormFieldWrapper)); exports.AddressInput = AddressInput; //# sourceMappingURL=address-input.js.map