Skip to content

Commit c0f875d

Browse files
committed
added for attribute to checkbox and radio labels and added specific id attribute to checkbox and radio inputs
1 parent 6321b95 commit c0f875d

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

app/concepts/matestack/ui/core/form/select/select.haml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,26 @@
2626
%div{id: component_id, ref: "select.multiple.#{attr_key}", "init-value": init_value}
2727
- if options[:options].is_a?(Hash)
2828
- options[:options].each do |key, value|
29-
%input{@tag_attributes,
29+
%input{@tag_attributes.except(:id),
30+
id: id_for_option(value),
3031
type: :checkbox,
3132
"#{model_binding}": input_key,
3233
"@change": "inputChanged(\"#{attr_key}\")",
3334
"value-type": options_type,
3435
name: value,
3536
value: key}/
36-
%label=value
37+
%label{for: id_for_option(value)}=value
3738
- if options[:options].is_a?(Array)
3839
- options[:options].each do |value|
39-
%input{@tag_attributes,
40+
%input{@tag_attributes.except(:id),
41+
id: id_for_option(value),
4042
type: :checkbox,
4143
"#{model_binding}": input_key,
4244
"@change": "inputChanged(\"#{attr_key}\")",
4345
"value-type": options_type,
4446
name: value,
4547
value: value}/
46-
%label=value
48+
%label{for: id_for_option(value)}=value
4749
%span{class: "errors", "v-if": error_key }
4850
%span{class: "error", "v-for": "error in #{error_key}"}
4951
{{ error }}
@@ -53,24 +55,26 @@
5355
%div{id: component_id, ref: "select.#{attr_key}", "init-value": init_value}
5456
- if options[:options].is_a?(Hash)
5557
- options[:options].each do |key, value|
56-
%input{@tag_attributes,
58+
%input{@tag_attributes.except(:id),
5759
type: :radio,
60+
id: id_for_option(value),
5861
"#{model_binding}": input_key,
5962
"@change": "inputChanged(\"#{attr_key}\")",
6063
"value-type": options_type,
6164
name: "#{attr_key}_#{key}",
6265
value: key}/
63-
%label=value
66+
%label{for: id_for_option(value)}=value
6467
- if options[:options].is_a?(Array)
6568
- options[:options].each do |value|
66-
%input{@tag_attributes,
69+
%input{@tag_attributes.except(:id),
6770
type: :radio,
71+
id: id_for_option(value),
6872
"#{model_binding}": input_key,
6973
"@change": "inputChanged(\"#{attr_key}\")",
7074
"value-type": options_type,
7175
name: "#{attr_key}_#{value}",
7276
value: value}/
73-
%label=value
77+
%label{for: id_for_option(value)}=value
7478
%span{class: "errors", "v-if": error_key }
7579
%span{class: "error", "v-for": "error in #{error_key}"}
7680
{{ error }}

app/concepts/matestack/ui/core/form/select/select.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ class Select < Matestack::Ui::Core::Component::Static
33

44
REQUIRED_KEYS = [:options]
55

6+
def setup
7+
if @tag_attributes[:id].nil?
8+
@tag_attributes[:id] = attr_key
9+
end
10+
end
11+
612
def input_key
713
'data["' + options[:key].to_s + '"]'
814
end
@@ -68,6 +74,10 @@ def init_value
6874
end
6975
end
7076

77+
def id_for_option value
78+
return "#{attr_key}_#{value}"
79+
end
80+
7181

7282
end
7383
end

0 commit comments

Comments
 (0)