@dock365/reform-fabric-fields
Version:
fabric fields reform
93 lines • 4.4 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var TextField_1 = require("office-ui-fabric-react/lib/TextField");
var ErrorHandlerHOC_1 = __importDefault(require("./ErrorHandlerHOC"));
var validator_1 = require("@dock365/validator");
var TextField = /** @class */ (function (_super) {
__extends(TextField, _super);
function TextField(props) {
var _this = _super.call(this, props) || this;
_this._onChange = function (e, value) {
// const inputValue = event.currentTarget.value;
// const value = this.props.localeString ? inputValue.toLocaleString() : inputValue;
if (_this.props.validationRules &&
_this.props.validationRules.type === validator_1.validationTypes.Number &&
!_this.props.customProps.localeString) {
if (isNaN(value)) {
_this.props.onChange(value);
}
else {
_this.props.onChange(Number(value));
}
return;
}
if (_this.props.onChange) {
_this.props.onChange(value);
}
// const value: any =
// (
// this.props.customProps.localeString &&
// this._localStringToNumber(event.currentTarget.value)) ||
// event.currentTarget.value;
// // tslint:disable-next-line:no-unused-expression
// if (this.props.onChange) {
// const isNumber = this.props.validationRules && this.props.validationRules.type === validationTypes.Number && !isNaN(Number(value));
// this.props.onChange(
// isNumber
// ?
// // _value.length - _value.lastIndexOf(".") === 1 ||
// // (_value.length - _value.lastIndexOf("0") === 1 && _value.lastIndexOf(".") > 0) ||
// (Number(value) == value && Number(value) !== value) &&
// !isNaN(Number(value))
// ? value
// : Number(value)
// : value,
// );
// }
};
_this._onChange = _this._onChange.bind(_this);
_this._onBlur = _this._onBlur.bind(_this);
return _this;
}
TextField.prototype.render = function () {
return (React.createElement(TextField_1.TextField, { readOnly: this.props.readOnly, value: this.props.value || this.props.value === 0 ? "" + this.props.value : this.props.value, componentRef: this.props.componentRef, label: this.props.label, onClick: this.props.onClick, placeholder: this.props.placeholder, maxLength: this.props.customProps.maxLength, onBlur: this._onBlur, onChange: this._onChange }));
};
TextField.prototype._onBlur = function (event) {
if (this.props.onBlur) {
this.props.onBlur(event.currentTarget.value);
}
this._onChange(event, this.props.value);
};
TextField.defaultProps = {
customProps: {},
value: "",
validationRules: {},
};
return TextField;
}(React.Component));
exports.default = ErrorHandlerHOC_1.default(TextField);
//# sourceMappingURL=TextField.js.map