File size: 1,783 Bytes
71174bc | 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 | <template>
<span>
<div :class="'form-check' + (toggle ? ' form-switch' : '')">
<input
class="form-check-input"
type="checkbox"
:title="text"
:disabled="disabled"
@input="handleInput"
:checked="modelValue"
:id="id"
:role="toggle ? 'switch' : ''"
/>
<label v-if="text !== ''" :for="id" class="form-check-label">
{{ text }}
</label>
</div>
<FormElementDescription
:description="description"
></FormElementDescription>
</span>
</template>
<script lang="ts">
import { Options, Vue } from "vue-class-component";
import { Prop } from "vue-property-decorator";
import FormElementDescription from "./FormElementDescription.vue";
/**
* FormCheckBox component
*/
@Options({
components: {
FormElementDescription,
},
})
export default class FormCheckBox extends Vue {
@Prop({ required: true }) modelValue!: boolean;
@Prop({ required: true }) id!: string;
@Prop({ default: "" }) text!: string;
@Prop({ default: false }) disabled!: boolean;
@Prop({ default: false }) toggle!: boolean;
@Prop() description!: string;
/**
* Let the parent component know of any changes.
*
* @param {any} e The value.
*/
handleInput(e: any) {
this.$emit("update:modelValue", e.target.checked);
// In some circumstances (e.g., changing values in an object), not reactive.
// Emit also "onChange" to signal the value has changed.
this.$emit("onChange");
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss"></style>
|