Last modified: 2014-01-05 15:16:40 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T60077, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 58077 - Validation of hidden fields keep form from validating during submit
Validation of hidden fields keep form from validating during submit
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
SemanticForms (Other open bugs)
REL1_20-branch
All Linux
: Unprioritized normal (vote)
: ---
Assigned To: Yaron Koren
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-12-06 03:50 UTC by Al Johnson
Modified: 2014-01-05 15:16 UTC (History)
1 user (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Al Johnson 2013-12-06 03:50:01 UTC
Testing for an upgrade from SemanticBundle 1.8alpha to:

Semantic Bundle (Version 1.8.0.5)
Semantic Forms (Version 2.5.3)    
Semantic Forms Inputs (Version 0.7)
Semantic MediaWiki (Version 1.8.0.5)   

I have a mandatory field using regex validation, but it is hidden because the value of a dropdown is not selected.  But, validation still fails during submit.  The main validation error message appears at the top of the form, but the specific error can't be seen next to it's field because it is in the hidden div.

Workaround: Removing the mandatory option and removing the regex rule allows the form to be submitted.

I'm trying to upgrade to 1.8.0.5 to get the fix for this very bug... didn't see a bug on it but I looked at the code changes and looked like it was addressed.
Comment 1 Yaron Koren 2013-12-06 03:52:53 UTC
What do you mean by "using regex validation"? What does the {{{field}}} tag look like?
Comment 2 Al Johnson 2013-12-06 03:56:41 UTC
NOTE: when I say 'hidden', I'm not referring to the hidden option for fields.  I'm speaking about a div that is hidden unless a dropdown value matches one of the "show on select" options.
Comment 3 Al Johnson 2013-12-06 03:57:22 UTC
{{{field|additional-url-vid-startsec|input type=regexp|regexp=/^\d{1,2}$/ |maxlength=2|size=1|mandatory}}}
Comment 4 Yaron Koren 2013-12-06 04:04:00 UTC
Right, I got the "hidden" part. Is the "mandatory" part necessary, given the regexp validation? Maybe it's the interplay of those two that's causing this bug... at least, that's my hope.
Comment 5 Al Johnson 2013-12-06 04:35:10 UTC
I just tried both combinations... without mandatory and without the regex.  Both have to be removed.
Comment 6 Al Johnson 2013-12-09 06:39:40 UTC
I think I found a fix:

[root@ip-10-0-1-101 libs]# diff SemanticForms.js.ori SemanticForms.js
771c771,772
<                               jQuery("#" + sfdata.validationFunctions[i].input).closest(".multipleTemplateStarter").length == 0 ) {
---
>                               jQuery("#" + sfdata.validationFunctions[i].input).closest(".multipleTemplateStarter").length == 0 &&
>                               jQuery("#" + sfdata.validationFunctions[i].input).closest(".hiddenBySF").length == 0) {
Comment 7 Al Johnson 2013-12-09 15:21:38 UTC
The fix above is not enough since the hidden stuff may not have had the hiddenBySF class added to them upon page load and it looks like mandatory but hidden fields are setup to be validated.  Is that by design?

So, this fix might not be valid:

[root@ip-10-0-1-101 libs]# diff SemanticForms.js.ori SemanticForms.js
733c733
<       jQuery("span.inputSpan.mandatoryFieldSpan").not(".hiddenBySF").each( function() {
---
>       jQuery("span.inputSpan.mandatoryFieldSpan").not(".hiddenBySF").not(":hidden").each( function() {
771c771,774
<                               jQuery("#" + sfdata.validationFunctions[i].input).closest(".multipleTemplateStarter").length == 0 ) {
---
>                               jQuery("#" + sfdata.validationFunctions[i].input).closest(".multipleTemplateStarter").length == 0 &&
>                               // My Change: fix for bug https://bugzilla.wikimedia.org/show_bug.cgi?id=58077
>                               jQuery("#" + sfdata.validationFunctions[i].input).closest(".hiddenBySF").length == 0 &&
>                               jQuery("#" + sfdata.validationFunctions[i].input + ":hidden").length == 0) {
Comment 8 Al Johnson 2013-12-10 14:46:33 UTC
Well, there was another problem with fields with default values and within disabled divs (hidden) still being submitted, so I had to add one more check.  Also, added the .parent() call to make sure that SF-hidden (but visible) fields DO get submitted.


# diff SemanticForms.js.ori SemanticForms.js
733c733
<       jQuery("span.inputSpan.mandatoryFieldSpan").not(".hiddenBySF").each( function() {
---
>       jQuery("span.inputSpan.mandatoryFieldSpan").not(".hiddenBySF").not(":hidden").each( function() {
771c771,774
<                               jQuery("#" + sfdata.validationFunctions[i].input).closest(".multipleTemplateStarter").length == 0 ) {
---
>                               jQuery("#" + sfdata.validationFunctions[i].input).closest(".multipleTemplateStarter").length == 0 &&
>                               // My Change: fix for bug https://bugzilla.wikimedia.org/show_bug.cgi?id=58077
>                               jQuery("#" + sfdata.validationFunctions[i].input).closest(".hiddenBySF").length == 0 &&
>                               jQuery("#" + sfdata.validationFunctions[i].input).parent().closest(":hidden").length == 0) {
776c779
<                                       )
---
>                                       ) {
777a781
>                               }
795a800,809
>
>               // My Change, like above for bug 58077
>               jQuery("input, select, textarea").each(function() {
>                       if(jQuery(this).parent().closest(":hidden").length != 0) {
>                               jQuery(this).attr('disabled', 'disabled')
>                               .addClass('disabledBySF')
>                               .addClass('hiddenBySF');
>                       }
>               });
>
Comment 9 Yaron Koren 2013-12-10 19:13:33 UTC
Does this fully work, as far as you know?
Comment 10 Al Johnson 2013-12-11 10:22:20 UTC
Seems to, but I'm no expert.
Comment 11 Gerrit Notification Bot 2013-12-30 16:11:52 UTC
Change 104514 had a related patch set uploaded by Yaron Koren:
Fix to avoid JS validation of fields hidden by "show on select"

https://gerrit.wikimedia.org/r/104514
Comment 12 Gerrit Notification Bot 2013-12-30 16:16:59 UTC
Change 104514 merged by jenkins-bot:
Fix to avoid JS validation of fields hidden by "show on select"

https://gerrit.wikimedia.org/r/104514
Comment 13 Yaron Koren 2013-12-30 16:35:55 UTC
Hi Al,

I looked into this - I definitely was able to replicate the problem with the "regexp" input type; but "mandatory" worked fine for me, without the need for changes. Your first fix (the two-line change) fixed the problem for me, for both regular and multiple-instance templates, so I checked it in. Could you please get the latest code and see if you're still having any problems?
Comment 14 Yaron Koren 2014-01-05 15:16:40 UTC
I believe this is fixed, so I'm marking it as "fixed" - feel free to re-open.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links