Skip to content

Commit

Permalink
fix(TMC-27327): Fix input number validation to display correct error …
Browse files Browse the repository at this point in the history
…msg (#5204)

Co-authored-by: Laurent Maillet <[email protected]>
  • Loading branch information
Gbacc and lmaillet authored Feb 26, 2024
1 parent e374251 commit 5d631f2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-owls-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/json-schema-form-core': patch
---

TMC-27327 - Fix input number validation to display correct error message
2 changes: 1 addition & 1 deletion packages/jsfc/src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/jsfc/src/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down

0 comments on commit 5d631f2

Please sign in to comment.