mw.widgets.DateInputWidget: Add required config
authorPrateek Saxena <prtksxna@gmail.com>
Mon, 7 Sep 2015 05:46:02 +0000 (11:16 +0530)
committerPrateek Saxena <prtksxna@gmail.com>
Mon, 7 Sep 2015 05:46:40 +0000 (11:16 +0530)
Change-Id: Ie3691d5239a512e1a4fa882c43c224c2de8d7598

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