Merge "mw.widgets.DateInputWidget: Add required config"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 7 Sep 2015 15:50:13 +0000 (15:50 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 7 Sep 2015 15:50:13 +0000 (15:50 +0000)
resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js

index 6b7f860..c8093bb 100644 (file)
         *     field when it's empty. Should be the same as `inputFormat`, but translated to the user's
         *     language. When not given, defaults to a translated version of 'YYYY-MM-DD' or 'YYYY-MM',
         *     depending on `precision`.
+        * @cfg {boolean} [required=false] Mark the field as required. Implies `indicator: 'required'`.
         */
        mw.widgets.DateInputWidget = function MWWDateInputWidget( config ) {
                // Config initialization
                config = $.extend( { precision: 'day' }, config );
+               if ( config.required ) {
+                       if ( config.indicator === undefined ) {
+                               config.indicator = 'required';
+                       }
+               }
 
                var placeholder;
                if ( config.placeholder ) {
                } );
 
                // Initialization
+               if ( config.required ) {
+                       this.$input.attr( 'required', 'required' );
+                       this.$input.attr( 'aria-required', 'true' );
+               }
                // Move 'tabindex' from this.$input (which is invisible) to the visible handle
                this.setTabIndexedElement( this.handle.$element );
                this.handle.$element