Support 'hide-if' parameters in OOUI HTMLForm
authorBartosz Dziewoński <matma.rex@gmail.com>
Sat, 30 Jul 2016 23:19:26 +0000 (01:19 +0200)
committerJforrester <jforrester@wikimedia.org>
Mon, 22 Aug 2016 15:42:22 +0000 (15:42 +0000)
commit89107070d14187915e760f8543579ec4d784620f
tree1f49d0d0d774387c7d0518a2263d36521d367c70
parent144ca9c5feaf9c7b0a8b9d5523233200e835e842
Support 'hide-if' parameters in OOUI HTMLForm

For plain HTML forms, we just put the required data in the 'data-hide-if'
attribute. For OOUI, it's not so easy - while we could just call
->setAttribute(...) on the FieldLayout, this would disappear when
infusing (since it's not part of the config), and we have no control over
when some piece of JavaScript decides to infuse the element. Even if we
managed to handle it first, infusing replaces the DOM nodes for elements
with new ones, which would "disable" our event handlers.

To solve this, I'm creating two new layouts HTMLFormFieldLayout and
HTMLFormActionFieldLayout (subclassing FieldLayout and ActionFieldLayout)
with a common trait (mixin) HTMLFormElement. This is all implemented both
in PHP and JS. Right now it only serves to carry the 'hide-if' data from
PHP to JS code, but I imagine it'll be extended in the future for other
HTMLForm features not yet present in the OOUI version (e.g. 'cloner'
fields).

The code in hide-if.js has been modified to work with jQuery objects or
with OOjs UI Widgets with minimal changes. I had to duplicate the map of
HTMLFormField classes to modules they require there (from autoinfuse.js),
which is ugly - I'm fixing this in a follow-up commit
I3da75706209cbc16b19cc3f02b355e58ca75fec9.

Bug: T141558
Change-Id: I3b06a6f75eed01d3e0bdc5dd33e1b40b7a2fc0a2
autoload.php
includes/htmlform/HTMLFormElement.php [new file with mode: 0644]
includes/htmlform/HTMLFormField.php
resources/Resources.php
resources/src/mediawiki/htmlform/autoinfuse.js
resources/src/mediawiki/htmlform/hide-if.js
resources/src/mediawiki/htmlform/htmlform.Element.js [new file with mode: 0644]