<commit_before><template>
    <b-form-group v-bind="$attrs" :label-class="labelClassWithRequired" :label-for="id" :state="fieldState">
        <template #default>
            <slot name="default" v-bind="{ id, field, state: fieldState }">
                <b-form-textarea v-if="inputType === 'textarea'" :id="id" v-model="field.$model"
                                 v-bind="inputAttrs" :state="fieldState"></b-form-textarea>
                <b-form-input v-else :type="inputType" :id="id" v-model="field.$model"
                              v-bind="inputAttrs" :state="fieldState"></b-form-input>
            </slot>

            <b-form-invalid-feedback :state="fieldState">
                <vuelidate-error :field="field"></vuelidate-error>
            </b-form-invalid-feedback>
        </template>

        <template #label="slotProps">
            <slot name="label" v-bind="slotProps"></slot>
            <span v-if="advanced" class="badge small badge-primary">
                <translate key="badge_advanced">Advanced</translate>
            </span>
        </template>
        <template #description="slotProps">
            <slot name="description" v-bind="slotProps"></slot>
        </template>

        <slot v-for="(_, name) in $slots" :name="name" :slot="name"/>
        <template v-for="(_, name) in filteredScopedSlots" :slot="name" slot-scope="slotData">
            <slot :name="name" v-bind="slotData"/>
        </template>
    </b-form-group>
</template>

<script>
import _ from "lodash";
import VuelidateError from "./VuelidateError";

export default {
    name: 'BWrappedFormGroup',
    components: {VuelidateError},
    props: {
        id: {
            type: String,
            required: true
        },
        field: {
            type: Object,
            required: true
        },
        inputType: {
            type: String,
            default: 'text'
        },
        inputAttrs: {
            type: Object,
            default() {
                return {};
            }
        },
        labelClass: {
            type: String,
            default: ''
        },
        advanced: {
            type: Boolean,
            default: false
        }
    },
    computed: {
        filteredScopedSlots() {
            return _.filter(this.$scopedSlots, (slot, name) => {
                return !_.includes([
                    'default', 'label', 'description'
                ], name);
            });
        },
        fieldState() {
            return this.field.$dirty ? !this.field.$error : null;
        },
        labelClassWithRequired () {
            let labelClass = this.labelClass;
            if (this.isRequired) {
                labelClass += ' required';
            }
            return labelClass;
        },
        isRequired() {
            return _.has(this.field, 'required');
        }
    }
}
</script><commit_msg>Make numeric input fields return numbers.<commit_after><template>
    <b-form-group v-bind="$attrs" :label-class="labelClassWithRequired" :label-for="id" :state="fieldState">
        <template #default>
            <slot name="default" v-bind="{ id, field, state: fieldState }">
                <b-form-textarea v-if="inputType === 'textarea'" :id="id" v-model="field.$model"
                                 :number="isNumeric" :trim="inputTrim" v-bind="inputAttrs"
                                 :state="fieldState"></b-form-textarea>
                <b-form-input v-else :type="inputType" :id="id" v-model="field.$model"
                              :number="isNumeric" :trim="inputTrim"
                              v-bind="inputAttrs" :state="fieldState"></b-form-input>
            </slot>

            <b-form-invalid-feedback :state="fieldState">
                <vuelidate-error :field="field"></vuelidate-error>
            </b-form-invalid-feedback>
        </template>

        <template #label="slotProps">
            <slot name="label" v-bind="slotProps"></slot>
            <span v-if="advanced" class="badge small badge-primary">
                <translate key="badge_advanced">Advanced</translate>
            </span>
        </template>
        <template #description="slotProps">
            <slot name="description" v-bind="slotProps"></slot>
        </template>

        <slot v-for="(_, name) in $slots" :name="name" :slot="name"/>
        <template v-for="(_, name) in filteredScopedSlots" :slot="name" slot-scope="slotData">
            <slot :name="name" v-bind="slotData"/>
        </template>
    </b-form-group>
</template>

<script>
import _ from "lodash";
import VuelidateError from "./VuelidateError";

export default {
    name: 'BWrappedFormGroup',
    components: {VuelidateError},
    props: {
        id: {
            type: String,
            required: true
        },
        field: {
            type: Object,
            required: true
        },
        inputType: {
            type: String,
            default: 'text'
        },
        inputNumber: {
            type: Boolean,
            default: false
        },
        inputTrim: {
            type: Boolean,
            default: false
        },
        inputAttrs: {
            type: Object,
            default() {
                return {};
            }
        },
        labelClass: {
            type: String,
            default: ''
        },
        advanced: {
            type: Boolean,
            default: false
        }
    },
    computed: {
        filteredScopedSlots() {
            return _.filter(this.$scopedSlots, (slot, name) => {
                return !_.includes([
                    'default', 'label', 'description'
                ], name);
            });
        },
        fieldState() {
            return this.field.$dirty ? !this.field.$error : null;
        },
        labelClassWithRequired() {
            let labelClass = this.labelClass;
            if (this.isRequired) {
                labelClass += ' required';
            }
            return labelClass;
        },
        isRequired() {
            return _.has(this.field, 'required');
        },
        isNumeric() {
            return this.inputNumber || this.inputType === "number";
        }
    }
}
</script>
{'fraction_non_alphanumeric': 0.1453198002255518, 'fraction_numerical': 0.0, 'mean_word_length': 1.5652892561983471, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6074472', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1696, 'n_words': 327}