目次

Vue.js 3.x LabeledCheckboxForm コンポーネント

要求

コード

LabeledCheckboxForm.js
import LabeledForm  from '/_export/code/vuejs/vue3/labeled_form?codeblock=0';
import CheckboxForm from '/_export/code/vuejs/vue3/checkbox_form?codeblock=0';
 
const LabeledCheckboxForm = {
  template: `
    <labeled-form
      :errors="errors"
      :label-text="labelText"
      :form-wrapper-classes="formWrapperClasses"
      :form-wrapper-styles="formWrapperStyles"
      :label-wrapper-classes="labelWrapperClasses"
      :label-wrapper-styles="labelWrapperStyles"
      :form-error-class="formErrorClass"
      :label-error-class="labelErrorClass"
    >
      <template #label v-if="!labelText">
        <slot name="label">
        </slot>
      </template>
      <checkbox-form
        :value="value"
        @update:value="updateValue"
        :options="options"
        :errors="errors"
        :control-wrapper-classes="controlWrapperClasses"
        :control-wrapper-styles="controlWrapperStyles"
        :control-classes="controlClasses"
        :control-styles="controlStyles"
        :option-classes="optionClasses"
        :option-styles="optionStyles"
        :control-error-class="controlErrorClass"
        :message-wrapper-classes="messageWrapperClasses"
        :message-wrapper-styles="messageWrapperStyles"
        :message-error-class="messageErrorClass"
      >
      </checkbox-form>
    </labeled-form>
  `,
  components: {
    labeledForm: LabeledForm,
    checkboxForm: CheckboxForm
  },
  props: {
    value:                 { type: Array },
    options:               { type: Array,  default: [] },
    errors:                { type: Array,  default: [] },
    labelText:             { type: String },
    formWrapperClasses:    { type: Array,  default: [] },
    formWrapperStyles:     { type: Object, default: {} },
    labelWrapperClasses:   { type: Array,  default: [] },
    labelWrapperStyles:    { type: Object, default: {} },
    controlWrapperClasses: { type: Array,  default: [] },
    controlWrapperStyles:  { type: Object, default: {} },
    controlClasses:        { type: Array,  default: [] },
    controlStyles:         { type: Object, default: {} },
    optionClasses:         { type: Array  },
    optionStyles:          { type: Object },
    messageWrapperClasses: { type: Array,  default: [] },
    messageWrapperStyles:  { type: Object, default: {} },
    formErrorClass:        { type: String, default: 'has-error' },
    labelErrorClass:       { type: String, default: 'text-danger' },
    controlErrorClass:     { type: String, default: 'is-invalid' },
    messageErrorClass:     { type: String, default: 'text-danger' },
  },
  setup(props, context) {
    function updateValue(v) {
      context.emit('update:value', v)
    }
    return { updateValue }
  }
};
export default LabeledCheckboxForm;

Props

value

options

errors

labelText

formWrapperClasses

formWrapperStyles

labelWrapperClasses

labelWrapperStyles

controlWrapperClasses

controlWrapperStyles

controlClasses

controlStyles

messageWrapperClasses

messageWrapperStyles

controlErrorClass

messageErrorClass

formErrorClass

labelErrorClass

Events

Demo

テーブルライクなレイアウト