Bug-Fix for subforms / repeatable fields#24832
Bug-Fix for subforms / repeatable fields#24832Lab5-Switzerland wants to merge 4 commits intojoomla:stagingfrom
Conversation
JS Form Validation for Subforms/Repeatable Fields Bug IE - Here is the Solution
### What needs to be fixed
In IE(11), Fields of a Subform or Repeatable Form dont validate - Seemingly.
Truth is : IE tries to validate the invisible Subform-repeatable<template> part of the subform - which ofc never contains values by its very nature - thus always producing errors
### Why this should be fixed
Because Client side form validation is essential. The bug described just exists, because repeatable fields are relatively new and this issue hasn't been addressed yet.
Also the soloution is beautifully simple and implemented in a minute.
### How would you fix it
Add the suggested line ( see below ) in to the File
**/media/system/js/validate-uncompressed.js , circa line 129**, right after
if(jQuery(fields[i]).hasClass('novalidate')) { continue; }
**ADD** the following line / code :
**if(jQuery(fields[i]).parents().is("template") ) { continue; }**
Explanation :
If a field is directly of indirectly encapsulated into a <template> tag, it is part of the subform's/repeatable-field's template (/reserve) part, BUT NOT the actual form in use - and thus is NOT to be treated as the part of the form in actual use. Thus, if the validator sees the a given field has as direct or indirect/farther parent a <template> element, the validator knows that this field is not part of the form and will skipp validation on this field. Viola.
Simple and beautiful solution.
( Reation of the validator is analogue to the line before, where it makes the validator skipp the field, it it sees a "novalidate" class attached ).
Ofc, the soloution must be transferred into the compressed version ( validate.js ) too.
### Side Effects expected
None.
|
2 note:
|
Great ideas ! 1.a) Are you shure it only affects an old IE ? 2.)
|
|
sorry, forget what I wrote :) it more like a workaround, but not a correct fix, |
| continue; | ||
| } | ||
| // If field is part of a subform-repeatable template, it's not supposed to be validated. | ||
| if(jQuery(fields[i]).parents().is("template") ) { |
There was a problem hiding this comment.
| if(jQuery(fields[i]).parents().is("template") ) { | |
| if (jQuery(fields[i]).parents().is("template")) { |
There was a problem hiding this comment.
OK, tidied up - Both lil changes implemented.
|
Please use the following minifier to submit the compressed version. |
Did now. Hope everything went well. |
|
Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/24832 |
|
Closing in favor of #24947. Thanks. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24832. |
JS Form Validation for Subforms/Repeatable Fields Bug IE - Here is the Solution
What needs to be fixed
In IE(11), Fields of a Subform or Repeatable Form dont validate - Seemingly.
Truth is : IE tries to validate the invisible Subform-repeatable part of the subform - which ofc never contains values by its very nature - thus always producing errors
Why this should be fixed
Because Client side form validation is essential. The bug described just exists, because repeatable fields are relatively new and this issue hasn't been addressed yet.
Also the soloution is beautifully simple and implemented in a minute.
How would you fix it
Add the suggested line ( see below ) in to the File
/media/system/js/validate-uncompressed.js , circa line 129, right after
if(jQuery(fields[i]).hasClass('novalidate')) { continue; }
ADD the following line / code :
if(jQuery(fields[i]).parents().is("template") ) { continue; }
Explanation :
If a field is directly of indirectly encapsulated into a tag, it is part of the subform's/repeatable-field's template (/reserve) part, BUT NOT the actual form in use - and thus is NOT to be treated as the part of the form in actual use. Thus, if the validator sees the a given field has as direct or indirect/farther parent a element, the validator knows that this field is not part of the form and will skipp validation on this field. Viola.
Simple and beautiful solution.
( Reation of the validator is analogue to the line before, where it makes the validator skipp the field, it it sees a "novalidate" class attached ).
Ofc, the soloution must be transferred into the compressed version ( validate.js ) too.
Side Effects expected
None.
Pull Request for Issue #24829
Summary of Changes
3 Lines of Code
Testing Instructions
Create any Subform. Some of the Fields in the Subform need to have validation required.
( e.g. add a field field of type="email", required="true", validate="email" )
Test in IE(11) by filling the form and trying to submit the form.
You'll get a form error, althou you have entered all fields correctly.
Expected result
Expected result in form with unfixed file (validate.js) would be, that you can simply submit the form propperly.
Actual result
Actual result in form with unfixed file (validate.js) is, that you get error messages, althou you seemingly entered everything correctly.
Documentation Changes Required