|
1 | 1 | require_relative '../utils' |
| 2 | +require_relative '../has_input_html_attributes' |
2 | 3 | require_relative '../has_errors' |
3 | 4 | module Matestack::Ui::Core::Form::Checkbox |
4 | 5 | class Checkbox < Matestack::Ui::Core::Component::Static |
5 | 6 | include Matestack::Ui::Core::Form::Utils |
| 7 | + include Matestack::Ui::Core::Form::HasInputHtmlAttributes |
6 | 8 | include Matestack::Ui::Core::Form::HasErrors |
7 | 9 |
|
8 | | - html_attributes :accept, :alt, :autocomplete, :autofocus, :checked, :dirname, :disabled, :form, :formaction, |
9 | | - :formenctype, :formmethod, :formnovalidate, :formtarget, :height, :list, :max, :maxlength, :min, :minlength, |
10 | | - :multiple, :name, :pattern, :placeholder, :readonly, :required, :size, :src, :step, :type, :value, :width |
11 | | - |
12 | 10 | requires :key |
13 | 11 | optional :value, :false_value, :multiple, :init, for: { as: :input_for }, label: { as: :input_label }, options: { as: :checkbox_options } |
14 | 12 |
|
@@ -40,10 +38,15 @@ def vue_attributes |
40 | 38 | ref: "input.#{attr_key}", |
41 | 39 | 'init-value': init_value, |
42 | 40 | 'v-bind:class': "{ '#{input_error_class}': #{error_key} }", |
| 41 | + 'value-type': value_type, |
43 | 42 | "#{v_model_type}": input_key, |
44 | 43 | }) |
45 | 44 | end |
46 | 45 |
|
| 46 | + def value_type |
| 47 | + item_value(checkbox_options.first).is_a?(Integer) ? Integer : nil |
| 48 | + end |
| 49 | + |
47 | 50 | def item_value(item) |
48 | 51 | item.is_a?(Array) ? item.last : item |
49 | 52 | end |
|
0 commit comments