import { computed } from 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.0.2/vue.esm-browser.js'; import { getWrapClass, generalizeOptions } from 'https://wws.jp/_export/code/vuejs/vue3/form_utils?codeblock=0'; const CheckboxForm = { template: `
`, props: { value: { type: Array }, options: { type: Array, default: [] }, errors: { type: Array, default: [] }, controlWrapperClasses: { type: Array, default: [] }, controlWrapperStyles: { type: Object, default: {} }, controlClasses: { type: Array, default: [] }, controlStyles: { type: Object, default: {} }, optionClasses: { type: Array, default: ['checkbox-inline'] }, optionStyles: { type: Object, default: {} }, messageWrapperClasses: { type: Array, default: [] }, messageWrapperStyles: { type: Object, default: {} }, controlErrorClass: { type: String, default: 'has-error' }, messageErrorClass: { type: String, default: 'text-danger' }, }, setup(props, context) { const computedControlWrapperClasses = computed(() => { return getWrapClass( props.errors, props.controlWrapperClasses, props.controlErrorClass ) }) const computedMessageWrapperClasses = computed(() => { return getWrapClass( props.errors, props.messageWrapperClasses, props.messageErrorClass ) }) const computedOptions = computed(() => { return generalizeOptions(props.options) }) function onChange(v) { const idx = props.value.indexOf(v) if (idx >= 0) { props.value.splice(idx, 1) } else { props.value.splice(0, 0, v) } context.emit('update:value', props.value) } function isChecked(v) { return (props.value.indexOf(v) >= 0) ? true : false } return { computedControlWrapperClasses, computedMessageWrapperClasses, computedOptions, isChecked, onChange } } }; export default CheckboxForm;