formio.js
formio.js copied to clipboard
[4.x] FIO-8660: Fixed email component re-rendering with unique setting option
Link to Jira Ticket
https://formio.atlassian.net/browse/FIO-8660
Description
Note: The issue is not reproducible on the 5.x version of the renderer because the 5.x renderer uses the core validator. However, as decided, the fix should be added to the 4.x renderer as well.
Issue: When the component has the unique
setting, it causes the validator to assign a unique
value to the validate
object of the component before running the checkValidity
method. On the next change, the component will check both the current and original components and will find a unique change, triggering a redraw of the component. This redraw attaches the default validate object and the validator reassigns the validate.unique
value. This cycle repeats with every change of the component. The issue is reproducible for the email component because, before the redraw, we save the cursor position using HTMLInputElement.selectionStart
. According to the documentation, this property is not available for inputs with the email type, which causes the cursor to always move to the beginning of the input after redrawing.
Solution: Save the original unique
setting value and restore it after validation. This prevents the component with the unique
setting from re-rendering on every change.
Checklist:
- [x] I have completed the above PR template
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation (if applicable)
- [x] My changes generate no new warnings
- [ ] My changes include tests that prove my fix is effective (or that my feature works as intended)
- [x] New and existing unit/integration tests pass locally with my changes
- [ ] Any dependent changes have corresponding PRs that are listed above