|
1 | 1 | /*! |
2 | 2 | * json-schema-form |
3 | | - * @version 1.0.0-alpha.1 |
| 3 | + * @version 1.0.0-alpha.2 |
4 | 4 | * @link https://github.com/json-schema-form/json-schema-form-core |
5 | 5 | * @license MIT |
6 | 6 | * Copyright (c) 2016 JSON Schema Form |
7 | 7 | */ |
8 | 8 | (function webpackUniversalModuleDefinition(root, factory) { |
9 | 9 | if(typeof exports === 'object' && typeof module === 'object') |
10 | | - module.exports = factory(); |
| 10 | + module.exports = factory(require("tv4")); |
11 | 11 | else if(typeof define === 'function' && define.amd) |
12 | | - define([], factory); |
| 12 | + define(["tv4"], factory); |
13 | 13 | else { |
14 | | - var a = factory(); |
| 14 | + var a = typeof exports === 'object' ? factory(require("tv4")) : factory(root["tv4"]); |
15 | 15 | for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; |
16 | 16 | } |
17 | | -})(this, function() { |
| 17 | +})(this, function(__WEBPACK_EXTERNAL_MODULE_10__) { |
18 | 18 | return /******/ (function(modules) { // webpackBootstrap |
19 | 19 | /******/ // The module cache |
20 | 20 | /******/ var installedModules = {}; |
@@ -111,7 +111,19 @@ return /******/ (function(modules) { // webpackBootstrap |
111 | 111 | }); |
112 | 112 | }); |
113 | 113 |
|
114 | | - var _schemaDefaults = __webpack_require__(9); |
| 114 | + var _validate = __webpack_require__(9); |
| 115 | + |
| 116 | + Object.keys(_validate).forEach(function (key) { |
| 117 | + if (key === "default") return; |
| 118 | + Object.defineProperty(exports, key, { |
| 119 | + enumerable: true, |
| 120 | + get: function get() { |
| 121 | + return _validate[key]; |
| 122 | + } |
| 123 | + }); |
| 124 | + }); |
| 125 | + |
| 126 | + var _schemaDefaults = __webpack_require__(11); |
115 | 127 |
|
116 | 128 | var schemaDefaultsImp = _interopRequireWildcard(_schemaDefaults); |
117 | 129 |
|
@@ -563,6 +575,81 @@ return /******/ (function(modules) { // webpackBootstrap |
563 | 575 |
|
564 | 576 | 'use strict'; |
565 | 577 |
|
| 578 | + Object.defineProperty(exports, "__esModule", { |
| 579 | + value: true |
| 580 | + }); |
| 581 | + exports.validate = validate; |
| 582 | + |
| 583 | + var _tv = __webpack_require__(10); |
| 584 | + |
| 585 | + var _tv2 = _interopRequireDefault(_tv); |
| 586 | + |
| 587 | + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 588 | + |
| 589 | + /** |
| 590 | + * Validate a value against its form definition and schema. |
| 591 | + * The value should either be of proper type or a string, some type |
| 592 | + * coercion is applied. |
| 593 | + * |
| 594 | + * @param {Object} form A merged form definition, i.e. one with a schema. |
| 595 | + * @param {Any} value the value to validate. |
| 596 | + * @return {Object} a tv4js result object. |
| 597 | + */ |
| 598 | + function validate(form, value) { |
| 599 | + if (!form) { |
| 600 | + return { valid: true }; |
| 601 | + }; |
| 602 | + |
| 603 | + var schema = form.schema; |
| 604 | + if (!schema) { |
| 605 | + return { valid: true }; |
| 606 | + }; |
| 607 | + |
| 608 | + // Input of type text and textareas will give us a viewValue of '' |
| 609 | + // when empty, this is a valid value in a schema and does not count as something |
| 610 | + // that breaks validation of 'required'. But for our own sanity an empty field should |
| 611 | + // not validate if it's required. |
| 612 | + if (value === '') { |
| 613 | + value = undefined; |
| 614 | + }; |
| 615 | + |
| 616 | + // Numbers fields will give a null value, which also means empty field |
| 617 | + if (form.type === 'number' && value === null) { |
| 618 | + value = undefined; |
| 619 | + }; |
| 620 | + |
| 621 | + // Version 4 of JSON Schema has the required property not on the |
| 622 | + // property itself but on the wrapping object. Since we like to test |
| 623 | + // only this property we wrap it in a fake object. |
| 624 | + var wrap = { type: 'object', 'properties': {} }; |
| 625 | + var propName = form.key[form.key.length - 1]; |
| 626 | + wrap.properties[propName] = schema; |
| 627 | + |
| 628 | + if (form.required) { |
| 629 | + wrap.required = [propName]; |
| 630 | + }; |
| 631 | + |
| 632 | + var valueWrap = {}; |
| 633 | + if (!!value) { |
| 634 | + valueWrap[propName] = value; |
| 635 | + }; |
| 636 | + |
| 637 | + return _tv2.default.validateResult(valueWrap, wrap); |
| 638 | + } /* Common code for validating a value against its form and schema definition */ |
| 639 | + ; |
| 640 | + |
| 641 | +/***/ }, |
| 642 | +/* 10 */ |
| 643 | +/***/ function(module, exports) { |
| 644 | + |
| 645 | + module.exports = tv4; |
| 646 | + |
| 647 | +/***/ }, |
| 648 | +/* 11 */ |
| 649 | +/***/ function(module, exports, __webpack_require__) { |
| 650 | + |
| 651 | + 'use strict'; |
| 652 | + |
566 | 653 | Object.defineProperty(exports, "__esModule", { |
567 | 654 | value: true |
568 | 655 | }); |
|
0 commit comments