diff --git a/.changeset/wise-owls-sing.md b/.changeset/wise-owls-sing.md new file mode 100644 index 00000000000..feea74dd726 --- /dev/null +++ b/.changeset/wise-owls-sing.md @@ -0,0 +1,5 @@ +--- +'@talend/json-schema-form-core': patch +--- + +TMC-27327 - Fix input number validation to display correct error message diff --git a/packages/jsfc/src/validate.js b/packages/jsfc/src/validate.js index 67ec600cd14..ee8651cf9c1 100644 --- a/packages/jsfc/src/validate.js +++ b/packages/jsfc/src/validate.js @@ -5,7 +5,7 @@ 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) { + if (event.target?.validity && event.target.validity.badInput) { return { valid: false, message: 'CUSTOM_ERROR_INVALID_INPUT' }; } break; diff --git a/packages/jsfc/src/validate.test.js b/packages/jsfc/src/validate.test.js index e6c61b1c605..1773b74840c 100644 --- a/packages/jsfc/src/validate.test.js +++ b/packages/jsfc/src/validate.test.js @@ -24,7 +24,7 @@ describe('validate.js', () => { 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 } } }; + const event = { target: { validity: { badInput: true } } }; let result = validate(testForm, value, event); expect(result.error.message).toBe('CUSTOM_ERROR_INVALID_INPUT'); });