Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311463

Change subject: mw.htmlform: Mark fields hidden with 'hide-if' as not required
......................................................................

mw.htmlform: Mark fields hidden with 'hide-if' as not required

Depends on I860b167ba01ceac09f5a74e4718a82d3d2545823 in OOjs UI.

Bug: T145440
Change-Id: I81d04dca6cbb499a15828fd33b01746b68c694da
---
M resources/src/mediawiki/htmlform/hide-if.js
1 file changed, 14 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/63/311463/1

diff --git a/resources/src/mediawiki/htmlform/hide-if.js 
b/resources/src/mediawiki/htmlform/hide-if.js
index 0fbbcbe..96ef34b 100644
--- a/resources/src/mediawiki/htmlform/hide-if.js
+++ b/resources/src/mediawiki/htmlform/hide-if.js
@@ -239,7 +239,20 @@
                                test = v[ 1 ];
                                // The .toggle() method works mostly the same 
for jQuery objects and OO.ui.Widget
                                func = function () {
-                                       self.toggle( !test() );
+                                       var shouldHide = test();
+                                       self.toggle( !shouldHide );
+                                       if ( !( self instanceof jQuery ) ) {
+                                               // self is a OO.ui.FieldLayout
+                                               // It may be impossible to 
submit a form with hidden required fields
+                                               if ( 
self.fieldWidget.setRequired ) {
+                                                       if ( shouldHide ) {
+                                                               
self.wasRequired = self.fieldWidget.isRequired();
+                                                               
self.fieldWidget.setRequired( false );
+                                                       } else if ( 
self.wasRequired !== undefined ) {
+                                                               
self.fieldWidget.setRequired( self.wasRequired );
+                                                       }
+                                               }
+                                       }
                                };
                                for ( i = 0; i < fields.length; i++ ) {
                                        // The .on() method works mostly the 
same for jQuery objects and OO.ui.Widget

-- 
To view, visit https://gerrit.wikimedia.org/r/311463
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I81d04dca6cbb499a15828fd33b01746b68c694da
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to