auto-views
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -20,2 +20,3 @@ /// <reference types="react" /> | ||
export declare class AutoForm extends React.Component<AutoFormProps, {}> { | ||
private validator; | ||
constructor(props: AutoFormProps); | ||
@@ -27,2 +28,2 @@ render(): JSX.Element; | ||
} | ||
export declare function makeFormEntry(formData: any, displayMode: DisplayMode, onEntryChange?: (key: string, e: React.FormEvent<HTMLDivElement>) => void): (property: SchemaProperty, key: string) => JSX.Element; | ||
export declare function makeFormEntry(formData: any, displayMode: DisplayMode, erroneousProps?: Array<SchemaProperty>, onEntryChange?: (key: string, e: React.FormEvent<HTMLDivElement>) => void): (property: SchemaProperty, key: string) => JSX.Element; |
@@ -24,2 +24,3 @@ "use strict"; | ||
var form_entry_1 = require("./form-entry"); | ||
var jsonschema_1 = require("jsonschema"); | ||
var DisplayMode; | ||
@@ -46,2 +47,3 @@ (function (DisplayMode) { | ||
var _this = _super.call(this, props) || this; | ||
_this.validator = new jsonschema_1.Validator(); | ||
_this.onEntryChange = function (key, e) { | ||
@@ -74,3 +76,6 @@ if (e.target && _this.props.onChange) { | ||
else { | ||
return this.props.repo.mapOverProperties(this.props.schemaId, makeFormEntry(this.props.formData, this.props.displayMode, this.onEntryChange)); | ||
var schema = this.props.repo.getSchema(this.props.schemaId); | ||
var validationErrors = this.validator.validate(this.props.formData, schema).errors; | ||
var erroneousProps = validationErrors.map(function (err) { return err.schema; }); | ||
return this.props.repo.mapOverProperties(this.props.schemaId, makeFormEntry(this.props.formData, this.props.displayMode, erroneousProps, this.onEntryChange)); | ||
} | ||
@@ -81,5 +86,9 @@ }; | ||
exports.AutoForm = AutoForm; | ||
function makeFormEntry(formData, displayMode, onEntryChange) { | ||
function makeFormEntry(formData, displayMode, erroneousProps, onEntryChange) { | ||
if (erroneousProps === void 0) { erroneousProps = []; } | ||
return function (property, key) { | ||
return React.createElement(form_entry_1.Entry, { "data-automation-id": form_entry_1.entrySelector(key), entryKey: key, title: property.title, displayMode: displayMode, type: property.type, value: formData[key], onChange: function (e) { return onEntryChange && onEntryChange(key, e); }, valid: property.isValid(formData[key]) }); | ||
var isValid = (erroneousProps.find(function (prop) { | ||
return prop == property; | ||
})) == undefined; | ||
return React.createElement(form_entry_1.Entry, { "data-automation-id": form_entry_1.entrySelector(key), entryKey: key, title: property.title, displayMode: displayMode, type: property.type, value: formData[key], onChange: function (e) { return onEntryChange && onEntryChange(key, e); }, valid: isValid }); | ||
}; | ||
@@ -86,0 +95,0 @@ } |
@@ -5,3 +5,2 @@ export declare class SchemaProperty { | ||
constructor(title: string, type: string); | ||
isValid(data: any): boolean; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsonschema_1 = require("jsonschema"); | ||
var SchemaProperty = (function () { | ||
@@ -9,11 +8,2 @@ function SchemaProperty(title, type) { | ||
} | ||
SchemaProperty.prototype.isValid = function (data) { | ||
var validator = new jsonschema_1.Validator(); | ||
var schema = { | ||
properties: { | ||
temporaryKey: { title: this.title, type: this.type } | ||
} | ||
}; | ||
return validator.validate({ temporaryKey: data }, schema).valid; | ||
}; | ||
return SchemaProperty; | ||
@@ -20,0 +10,0 @@ }()); |
{ | ||
"name": "auto-views", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "Common, fully-tested, strictly-typed, Wix-styled, auto views library", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -6,13 +6,3 @@ import {Validator, Schema} from 'jsonschema'; | ||
constructor(public title:string, public type: string){} | ||
public isValid(data: any):boolean { | ||
const validator = new Validator(); | ||
const schema = { | ||
properties:{ | ||
temporaryKey: {title:this.title, type:this.type} | ||
}} as Schema; | ||
return validator.validate({temporaryKey:data},schema).valid; | ||
} | ||
} | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53734
0