vue-rails-form-builder 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +42 -0
- data/lib/vue-rails-form-builder/form_builder.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa3c6e7c44cc969b0f7f0c9622dfdd3eb317fdd8
|
4
|
+
data.tar.gz: 4dd0e717fa65a2dbe708eb9700e14494fc89f70b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 896d2262ca0bd4d6512f126a5c9be4935a72d835667b3c2abafd0a0d83edf6056be43d756326706486b190faf4f4ff1a99c26e579a43221d69928aa16a19e982
|
7
|
+
data.tar.gz: 1519211c095a49275707318205e3611281ec44cd8f52f20e7cbe21ec46a1f36ce53e5d25451085b038ac316a1f15c56ff193ce48d8bbd4e870a1fdf5f4820045
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -223,6 +223,48 @@ Example:
|
|
223
223
|
<% end %>
|
224
224
|
```
|
225
225
|
|
226
|
+
The `vue_prefix` method of the Form Builder
|
227
|
+
-------------------------------------------
|
228
|
+
|
229
|
+
When you build HTML forms using `vue_form_for`, the form builder has the
|
230
|
+
`vue_prefix` method that returns the *prefix string* to the Vue.js property names.
|
231
|
+
|
232
|
+
See the following code:
|
233
|
+
|
234
|
+
```erb
|
235
|
+
<%= vue_form_for User.new do |f| %>
|
236
|
+
<%= f.text_field :name %>
|
237
|
+
<%= f.submit "Create", disabled: "user.name === ''" %>
|
238
|
+
<% end %>
|
239
|
+
```
|
240
|
+
|
241
|
+
The `vue_prefix` method of the form builder (`f`) returns the string `"user"`
|
242
|
+
so that you can rewrite the third line of the example above like this:
|
243
|
+
|
244
|
+
```erb
|
245
|
+
<%= f.submit "Create", disabled: "#{f.vue_prefix}.name === ''" %>
|
246
|
+
```
|
247
|
+
|
248
|
+
This method is convenient especially when the form has nested attributes:
|
249
|
+
|
250
|
+
```erb
|
251
|
+
<%= vue_form_for @user do |f| %>
|
252
|
+
<%= f.text_field :name %>
|
253
|
+
<%= f.fields_for :emails do |g| %>
|
254
|
+
<%= g.text_field :address,
|
255
|
+
bind: { disabled: "user.emails_attributes[#{g.index}]._destroy" } %>
|
256
|
+
<%= g.check_box :_destroy if g.object.persisted? %>
|
257
|
+
<% end %>
|
258
|
+
<%= f.submit "Create", disabled: "user.name === ''" %>
|
259
|
+
<% end %>
|
260
|
+
```
|
261
|
+
|
262
|
+
Using the `vue_prefix` method, you can rewrite the fifth line more concisely:
|
263
|
+
|
264
|
+
```erb
|
265
|
+
bind: { disabled: g.vue_prefix + "._destroy" } %>
|
266
|
+
```
|
267
|
+
|
226
268
|
Data Initialization
|
227
269
|
-------------------
|
228
270
|
|
@@ -47,5 +47,13 @@ module VueRailsFormBuilder
|
|
47
47
|
resolve_vue_options(options)
|
48
48
|
super(value, options, &block)
|
49
49
|
end
|
50
|
+
|
51
|
+
def vue_prefix
|
52
|
+
path = @object_name.gsub(/\[/, ".").gsub(/\]/, "").split(".")
|
53
|
+
if @options[:vue_scope]
|
54
|
+
path[0] = @options[:vue_scope]
|
55
|
+
end
|
56
|
+
path.join(".").gsub(/\.(\d+)/, '[\1]')
|
57
|
+
end
|
50
58
|
end
|
51
59
|
end
|