simplr-forms-dom
Version:
DOM components for simplr-forms.
308 lines (284 loc) • 11.1 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("simplr-forms-core"), require("react"), require("./abstractions"), require("typed-immutable-record"));
else if(typeof define === 'function' && define.amd)
define(["simplr-forms-core", "react", "./abstractions", "typed-immutable-record"], factory);
else {
var a = typeof exports === 'object' ? factory(require("simplr-forms-core"), require("react"), require("./abstractions"), require("typed-immutable-record")) : factory(root["simplr-forms-core"], root["react"], root["./abstractions"], root["typed-immutable-record"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_8__, __WEBPACK_EXTERNAL_MODULE_9__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 7);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ }),
/* 2 */,
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
;
var __extends = (this && this.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = __webpack_require__(1);
var simplr_forms_core_1 = __webpack_require__(0);
var Form = (function (_super) {
__extends(Form, _super);
function Form() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.SetElementRef = function (element) {
_this.Element = element;
_this.FormStore.SetSubmitCallback(function () {
element.dispatchEvent(new Event("submit"));
});
};
_this.FormSubmitHandler = function (event) {
if (_this.props.preventSubmitDefaultAndPropagation) {
event.preventDefault();
event.stopPropagation();
}
if (!_this.ShouldFormSubmit()) {
return;
}
// TODO: Touch all fields to validate
if (_this.props.onSubmit == null) {
return;
}
var result = _this.props.onSubmit(event, _this.FormStore);
_this.Submit(result);
};
return _this;
}
Form.prototype.render = function () {
return React.createElement("form", { ref: this.SetElementRef, onSubmit: this.FormSubmitHandler }, this.props.children);
};
return Form;
}(simplr_forms_core_1.BaseForm));
Form.defaultProps = {
preventSubmitDefaultAndPropagation: true
};
exports.Form = Form;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
;
var __extends = (this && this.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = __webpack_require__(1);
var typed_immutable_record_1 = __webpack_require__(9);
var simplr_forms_core_1 = __webpack_require__(0);
var Submit = (function (_super) {
__extends(Submit, _super);
function Submit() {
return _super !== null && _super.apply(this, arguments) || this;
}
Submit.prototype.OnStoreUpdated = function () {
var formStore = this.FormStore.GetState();
var newState = typed_immutable_record_1.recordify({
Error: formStore.Form.Error,
Validating: formStore.Form.Validating,
Submitting: formStore.Form.Submitting,
Pristine: formStore.Form.Pristine
});
if (!newState.equals(this.state)) {
this.setState(function () { return newState; });
}
};
Object.defineProperty(Submit.prototype, "Disabled", {
get: function () {
// TODO: Disabled....
return false;
},
enumerable: true,
configurable: true
});
Submit.prototype.render = function () {
return React.createElement("button", { type: "submit", disabled: this.Disabled }, this.props.children);
};
return Submit;
}(simplr_forms_core_1.BaseContainer));
exports.Submit = Submit;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
;
var __extends = (this && this.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = __webpack_require__(1);
var base_dom_field_1 = __webpack_require__(8);
var Text = (function (_super) {
__extends(Text, _super);
function Text() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.OnChangeHandler = function (event) {
_this.OnValueChange(_this.GetValueFromEvent(event));
var newValue = _this.FormStore.GetField(_this.FieldId).Value;
if (_this.props.onChange != null) {
_this.props.onChange(event, newValue, _this.FieldId, _this.FormId);
}
// TODO: FormProps.OnFieldChange
};
return _this;
}
Text.prototype.GetValueFromEvent = function (event) {
return event.currentTarget.value;
};
Object.defineProperty(Text.prototype, "RawInitialValue", {
get: function () {
if (this.props != null && this.props.value != null) {
return this.props.value;
}
return this.DefaultValue;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Text.prototype, "DefaultValue", {
get: function () {
if (this.props != null && this.props.defaultValue != null) {
return this.props.defaultValue;
}
return "";
},
enumerable: true,
configurable: true
});
Object.defineProperty(Text.prototype, "IsDisabled", {
get: function () {
var disabled;
// TODO: FormProps.Disabled and FieldsGroupProps.Disabled
if (this.props.disabled != null) {
disabled = this.props.disabled;
}
return disabled;
},
enumerable: true,
configurable: true
});
Text.prototype.renderField = function () {
return React.createElement("input", { type: "text", name: this.FieldId, value: this.Value, onChange: this.OnChangeHandler, disabled: this.IsDisabled });
};
return Text;
}(base_dom_field_1.BaseDomField));
exports.Text = Text;
/***/ }),
/* 6 */,
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
;
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(__webpack_require__(3));
__export(__webpack_require__(5));
__export(__webpack_require__(4));
/***/ }),
/* 8 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_8__;
/***/ }),
/* 9 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_9__;
/***/ })
/******/ ]);
});