Socket
Socket
Sign inDemoInstall

@talend/json-schema-form-core

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@talend/json-schema-form-core - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

dist/index.js.LICENSE.txt

6

CHANGELOG.md
# @talend/json-schema-form-core
## 1.1.1
### Patch Changes
- f77b6a9b7: TDOPS-3372 - validate input value for integer fields
## 1.1.0

@@ -4,0 +10,0 @@

7

package.json
{
"name": "@talend/json-schema-form-core",
"version": "1.1.0",
"version": "1.1.1",
"description": "JSON-Schema and JSON-UI-Schema utilities for form generation.",

@@ -42,6 +42,5 @@ "main": "dist/index.js",

"devDependencies": {
"@talend/scripts-core": "^11.7.1",
"@talend/scripts-preset-react-lib": "^11.0.3",
"@talend/scripts-core": "^12.0.0",
"@talend/scripts-preset-react-lib": "^14.0.0",
"@types/chai": "^3.5.2",
"@types/mocha": "^2.2.48",
"@types/node": "^6.14.13",

@@ -48,0 +47,0 @@ "json-refs": "^3.0.15",

/* Common code for validating a value against its form and schema definition */
import tv4 from 'tv4';
function validateTypeSpecificInput(inputType = '', event = {}) {
switch (inputType) {
case 'number':
// If the user types a non-integer value, the value is emptied by browser but still displayed in UI
if (event.target?.validity && !event.target.validity.valid) {
return { valid: false, message: 'CUSTOM_ERROR_INVALID_INPUT' };
}
break;
default:
break;
}
return { valid: true };
}
/**

@@ -11,5 +25,6 @@ * Validate a value against its form definition and schema.

* @param {Any} value the value to validate.
* @param {Object} event for input types in which the values are not available in form
* @return {Object} a tv4js result object.
*/
export function validate(form, value) {
export function validate(form, value, event) {
if (!form) {

@@ -32,5 +47,5 @@ return { valid: true };

// Numbers fields will give a null value, which also means empty field
if (form.type === 'number' && value === null) {
value = undefined;
const error = validateTypeSpecificInput(form.type, event);
if (!error.valid && error.message) {
return { valid: false, error: { message: error.message } };
}

@@ -37,0 +52,0 @@

@@ -16,3 +16,3 @@ import chai from 'chai';

let value = 'Batman';
let result = validate(form, value);
let result = validate(form, value, {});
should.not.exist(result.error);

@@ -26,6 +26,14 @@ result.missing.should.be.a('array');

let value = [0];
let result = validate(form, value);
let result = validate(form, value, {});
result.error.message.should.eq('Invalid type: array (expected string)');
});
it('should return an error object with a message "CUSTOM_ERROR_INVALID_INPUT" when the integer value is not valid', () => {
let value = 'stringValue';
const testForm = { type: 'number', key: ['hero'], schema: { type: 'number' } };
const event = { target: { validity: { valid: false } } };
let result = validate(testForm, value, event);
result.error.message.should.eq('CUSTOM_ERROR_INVALID_INPUT');
});
});
});

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc