Skip to content

Commit f3e46c3

Browse files
committed
Allow the form builder to resolve :v option.
1 parent aaf098e commit f3e46c3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/vue-form-for/form_builder.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,40 @@ class FormBuilder < ActionView::Helpers::FormBuilder
33
(field_helpers - [:label, :fields_for]).each do |selector|
44
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
55
def #{selector}(method, options = {})
6+
resolve_vue_options(options)
67
options[:"v-model"] ||= "\#{@object_name}.\#{method}"
78
super(method, options)
89
end
910
RUBY_EVAL
1011
end
12+
13+
def label(method, text = nil, options = {}, &block)
14+
resolve_vue_options(options)
15+
super(method, text, options, &block)
16+
end
17+
18+
def submit(value = nil, options = {})
19+
resolve_vue_options(options)
20+
super(value, options)
21+
end
22+
23+
def button(value = nil, options = {}, &block)
24+
resolve_vue_options(options)
25+
super(value, options, &block)
26+
end
27+
28+
private def resolve_vue_options(options)
29+
if options[:v].kind_of?(Hash)
30+
h = options.delete(:v)
31+
h.each do |key, value|
32+
case key
33+
when /\A[:@]/
34+
options[key] = value
35+
else
36+
options[:"v-#{key}"] = value
37+
end
38+
end
39+
end
40+
end
1141
end
1242
end

0 commit comments

Comments
 (0)