Skip to content

Commit

Permalink
Merge pull request #5687 from formio/FIO-8645-day-component-required-…
Browse files Browse the repository at this point in the history
…validation-error-not-correct

FIO-8645: day component required validation error not correct
  • Loading branch information
brendanbond authored Jul 17, 2024
2 parents b600913 + 925e544 commit d5246a5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/components/day/Day.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
comp4,
comp5,
comp6,
comp7
comp7,
comp8
} from './fixtures';
import PanelComponent from '../panel/Panel';

Expand Down Expand Up @@ -232,11 +233,11 @@ describe('Day Component', () => {
dayComponent.refs.day.dispatchEvent(new Event('input'));

setTimeout(() => {
assert(dayComponent._errors.length && dayComponent._errors[0].message === 'requiredDayField', 'Day should be valid while changing');
assert(dayComponent._errors.length && dayComponent._errors[0].message === 'Day is required', 'Day should be valid while changing');
dayComponent.refs.day.dispatchEvent(new Event('blur'));

setTimeout(() => {
assert(dayComponent._errors.length && dayComponent._errors[0].message === 'requiredDayField', 'Should set error after Day component was blurred');
assert(dayComponent._errors.length && dayComponent._errors[0].message === 'Day is required', 'Should set error after Day component was blurred');
done();
}, 200);
}, 200);
Expand Down Expand Up @@ -265,6 +266,7 @@ describe('Day Component', () => {
}, 500);
}).catch(done);
});

it('Should translate placeholder text', () => {
const element = document.createElement('div');
return Formio.createForm(element, comp7, {
Expand All @@ -283,4 +285,16 @@ describe('Day Component', () => {
assert.equal(dayComponent.refs.year.placeholder, 'Year3');
})
});

it('Should translate requiredDayField to {{ field }} is required', (done) => {
Formio.createForm(document.createElement('div'), comp8, {}).then((form) => {
const dayComponent = form.getComponent('dayTable');
const buttonComponent = form.getComponent('submit');
buttonComponent.refs.button.click();
setTimeout(()=>{
assert.equal(dayComponent.errors[0].message, 'Day - Table is required');
done();
},200);
});
});
});
38 changes: 38 additions & 0 deletions src/components/day/fixtures/comp8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export default {
"components": [
{
"label": "Day - Table",
"hideInputLabels": false,
"inputsLabelPosition": "top",
"useLocaleSettings": false,
"alwaysEnabled": false,
"tableView": false,
"fields": {
"day": {
"hide": false,
"required": true
},
"month": {
"hide": false,
"required": true
},
"year": {
"hide": false,
"required": true
}
},
"key": "dayTable",
"type": "day",
"input": true
},
{
"label": "Submit",
"showValidations": false,
"alwaysEnabled": false,
"tableView": false,
"key": "submit",
"type": "button",
"input": true
}
]
}
3 changes: 2 additions & 1 deletion src/components/day/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import comp4 from './comp4';
import comp5 from './comp5';
import comp6 from './comp6';
import comp7 from './comp7';
export { comp1, comp2, comp3, comp4, comp5, comp6, comp7 };
import comp8 from './comp8';
export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8 };
5 changes: 4 additions & 1 deletion src/translations/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@ export default {
reCaptchaTokenNotSpecifiedError: 'ReCAPTCHA: Token is not specified in submission',
apiKey: 'API Key is not unique: {{key}}',
typeRemaining: '{{ remaining }} {{ type }} remaining.',
typeCount: '{{ count }} {{ type }}'
typeCount: '{{ count }} {{ type }}',
requiredDayField: '{{ field }} is required',
requiredMonthField: '{{ field }} is required',
requiredYearField: '{{ field }} is required'
};

0 comments on commit d5246a5

Please sign in to comment.