All files / lib/components form-fieldset.vue

67.35% Statements 33/49
59.26% Branches 32/54
94.74% Functions 18/19
67.35% Lines 33/49
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 19118x 18x 18x   18x 18x                     18x         18x                                                                     18x   94x             94x     1x     1x     94x         94x     94x     93x       93x     94x     94x     94x     94x     94x         313x         313x 313x     313x 313x       94x     219x                     94x         94x                                     352x 352x                                                        
<template>
    <div :class="['form-group','row',inputState]"
    I     :id="id || null"
         role="group"
         :aEria-describedby="describedBy"
    >
        <label v-if="label || $slots['label']"
               :for="target"
               :id="labelId"
               :class="[labelSrOnly ? 'sr-only' : 'col-form-label',labelLayout,labelAlignClass]"
        >
            <slot name="label"><span v-html="label"></span></slot>
        </label>
        <div :class="inputLayout" ref="content">
            <slot></slot>
            <div v-if="feedback || $slots['feedback']"
                 class="form-text form-control-feedback"
                 :id="feedbackId"
                 role="alert"
                 aria-live="assertive"
                 aria-atomic="true"
            >
                <slot name="feedback"><span v-html="feedback"></span></slot>
            </div>
            <small v-if="description || $slots['description']"
                   class="form-text text-muted"
                   :id="descriptionId"
            >
                <slot name="description"><span v-html="description"></span></slot>
            </small>
        </div>
    </div>
</template>
 
<script>
    import {warn} from '../utils';
 
    const INPUT_SELECTOR = [
        '[role="radiogroup"]',
        'input',
        'select',
        'textarea',
        '.form-control',
        '.form-control-static',
        '.dropdown',
        '.dropup'
    ].join(',');
 
    export default {
        data() {
            return {
                target: null
            };
        },
        computed: {
            labelId() {
                return (this.id && this.label) ? (this.id + '__BV_label_') : null;
            },
            descriptionId() {
                return (this.id && this.description) ? (this.id + '__BV_description_') : null;
            },
            feedbackId() {
                return (this.id && this.feedback) ? (this.id + '__BV_feedback_') : null;
            },
            describedBy() {
                if (this.id && (this.label || this.feedback || this.description)) {
                    return [
                        this.labelId,
                        this.descriptionId,
                        this.feedbackId
                    ].filter(i => i).join(' ');
                }
                return null;
            },
            inpuItState() {
                return this.state ? `has-${this.state}` : '';
            },
            computedLabelCols() {
                if (this.labelSize) {
                    warn('b-form-fieldset: prop label-size has been deprecated. Use label-cols instead');
                    return this.labelSize;
                }
                return this.labelCols;
            },
            labelLayout() {
                Iif (this.labelSrOnly) {
                    return null;
                }
                return this.horizontal ? ('col-sm-' + this.computedLabelCols) : 'col-12';
            },
            labelAlignClass() {
                if (this.labelSrOnly) {
                I    return null;
                }
                return this.labelTextAlign ? `text-${this.labelTextAlign}` : null;
            },
            inputLayout() {
                return this.horizontal ? ('col-sm-' + (12 - this.computedLabelCols)) : 'col-12';
            }I
        },
        methods: {
            updateTarget() {
                if (this.labelFor) {
                    // User supplied for target
                    return this.labelFor;
                }
                // Else find first input with ID
                const content = this.$refs.content;
                if (!content) {
                I    return null;
                }
                const input = content.querySelector(this.inputSelector);
                this.target = (input && input.id) ? input.id : null;
            }
        },
        mounted(I) {
            this.updateTarget();
        },
        updated() {
            this.updateTarget();
        },
        props: {
            id: {
                type: String,
                default: null
            },
            labelFor: {
                type: String,
                default() {
                    if (this && this.for) {
                        // Deprecate prop for
                        warn("b-form-fieldet: prop 'for' has been deprecated. Use 'label-for' instead");
                        return this.for;
                    }
                    return null;
                }
            },
            for: {I
                type: String,
                default: null
            },
            state: {
                type: String,
                default: null
            },
            horizontal: {
                type: Boolean,
                default: false
            },
            labelCols: {
                type: Number,
                default: 3,
                validator(value) {
                    if (value >= 1 && value <= 11) {
                        return true;
                    }
                    warn('b-form-fieldset: label-cols must be a value between 1 and 11');
                    return false;
                }
            },
            labelSize: {
                typeE: Number
            },
            labelTextAlign: {
                type: String,
                default: null
            },
            label: {
                type: String,
                default: null
            },
            labelSrOnly: {
                type: Boolean,
                default: false
            },
            description: {
                type: String,
                default: null
            },
            feedback: {
                type: String,
                default: null
            },
            inputSelector: {
                type: String,
                default: INPUT_SELECTOR
            }
        }
    };
</script>