# all files / src/layouts/ FieldsetLayout.js

79.17% Statements 19/24
50% Branches 4/8
100% Functions 1/1
79.17% Lines 19/24

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109

    1×

    112×

    112×

    112×
    112×
    112×

    112×
    112×

    112×

    112×

    112×
    112×

    112×
    74×

    1×
    1×
    1×
    1×

    1×
     /**
     * FieldsetLayouts are composed of one or more {@link OO.ui.FieldLayout FieldLayouts},
     * which each contain an individual widget and, optionally, a label. Each Fieldset can be
     * configured with a label as well. For more information and examples,
     * please see the [OOjs UI documentation on MediaWiki][1].
     *
     *     @example
     *     // Example of a fieldset layout
     *     var input1 = new OO.ui.TextInputWidget( {
     *         placeholder: 'A text input field'
     *     } );
     *
     *     var input2 = new OO.ui.TextInputWidget( {
     *         placeholder: 'A text input field'
     *     } );
     *
     *     var fieldset = new OO.ui.FieldsetLayout( {
     *         label: 'Example of a fieldset layout'
     *     } );
     *
     *     fieldset.addItems( [
     *         new OO.ui.FieldLayout( input1, {
     *             label: 'Field One'
     *         } ),
     *         new OO.ui.FieldLayout( input2, {
     *             label: 'Field Two'
     *         } )
     *     ] );
     *     $( 'body' ).append( fieldset.$element );
     *
     * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Layouts/Fields_and_Fieldsets
     *
     * @class
     * @extends OO.ui.Layout
     * @mixins OO.ui.mixin.IconElement
     * @mixins OO.ui.mixin.LabelElement
     * @mixins OO.ui.mixin.GroupElement
     *
     * @constructor
     * @param {Object} [config] Configuration options
     * @cfg {OO.ui.FieldLayout[]} [items] An array of fields to add to the fieldset. See OO.ui.FieldLayout for more information about fields.
     * @cfg {string|OO.ui.HtmlSnippet} [help] Help text. When help text is specified, a "help" icon will appear
     *  in the upper-right corner of the rendered field; clicking it will display the text in a popup.
     *  For important messages, you are advised to use `notices`, as they are always shown.
     * @cfg {jQuery} [$overlay] Passed to OO.ui.PopupButtonWidget for help popup, if `help` is given.
     *  See <https://www.mediawiki.org/wiki/OOjs_UI/Concepts#Overlays>.
     */
    OO.ui.FieldsetLayout = function OoUiFieldsetLayout( config ) {
    	// Configuration initialization
    	config = config || {};

    	// Parent constructor
    	OO.ui.FieldsetLayout.parent.call( this, config );

    	// Mixin constructors
    	OO.ui.mixin.IconElement.call( this, config );
    	OO.ui.mixin.LabelElement.call( this, config );
    	OO.ui.mixin.GroupElement.call( this, config );

    	// Properties
    	this.$header = $( '<legend>' );
    	Iif ( config.help ) {
    		this.popupButtonWidget = new OO.ui.PopupButtonWidget( {
    			$overlay: config.$overlay,
    			popup: {
    				padded: true
    			},
    			classes: [ 'oo-ui-fieldsetLayout-help' ],
    			framed: false,
    			icon: 'info'
    		} );
    		if ( config.help instanceof OO.ui.HtmlSnippet ) {
    			this.popupButtonWidget.getPopup().$body.html( config.help.toString() );
    		} else {
    			this.popupButtonWidget.getPopup().$body.text( config.help );
    		}
    		this.$help = this.popupButtonWidget.$element;
    	} else {
    		this.$help = $( [] );
    	}

    	// Initialization
    	this.$header
    		.addClass( 'oo-ui-fieldsetLayout-header' )
    		.append( this.$icon, this.$label, this.$help );
    	this.$group.addClass( 'oo-ui-fieldsetLayout-group' );
    	this.$element
    		.addClass( 'oo-ui-fieldsetLayout' )
    		.prepend( this.$header, this.$group );
    	if ( Array.isArray( config.items ) ) {
    		this.addItems( config.items );
    	}
    };

    /* Setup */

    OO.inheritClass( OO.ui.FieldsetLayout, OO.ui.Layout );
    OO.mixinClass( OO.ui.FieldsetLayout, OO.ui.mixin.IconElement );
    OO.mixinClass( OO.ui.FieldsetLayout, OO.ui.mixin.LabelElement );
    OO.mixinClass( OO.ui.FieldsetLayout, OO.ui.mixin.GroupElement );

    /* Static Properties */

    /**
     * @static
     * @inheritdoc
     */
    OO.ui.FieldsetLayout.static.tagName = 'fieldset';