vue-rails-form-builder 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb60b602f0b4bf94d40f088362b3fdeef4ca89a7
4
- data.tar.gz: a3725747492dfd19ddf8caf961d1f7828c301f57
3
+ metadata.gz: aa3c6e7c44cc969b0f7f0c9622dfdd3eb317fdd8
4
+ data.tar.gz: 4dd0e717fa65a2dbe708eb9700e14494fc89f70b
5
5
  SHA512:
6
- metadata.gz: '0768d856715debf23597021ed7e2d4db8b835eb93363bf5541d6c0896d929bc414354dd48f029dfc9173e3131403ea567f5e395a5ddf434cdf083d71ff607a76'
7
- data.tar.gz: fa2b5fdf2dcc72e8045f97bd3ddd62a36a04acea6485791c958a3df412831ef36383c9a8f56b045c8e7d7f578b700229aa8fa1165cd89a62531530fe32d126f8
6
+ metadata.gz: 896d2262ca0bd4d6512f126a5c9be4935a72d835667b3c2abafd0a0d83edf6056be43d756326706486b190faf4f4ff1a99c26e579a43221d69928aa16a19e982
7
+ data.tar.gz: 1519211c095a49275707318205e3611281ec44cd8f52f20e7cbe21ec46a1f36ce53e5d25451085b038ac316a1f15c56ff193ce48d8bbd4e870a1fdf5f4820045
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG - vue-rails-form-builder
2
2
 
3
+ ## 0.8.0 (2017-11-11)
4
+
5
+ * Add `vue_prefix` method to the form builder.
6
+
3
7
  ## 0.7.0 (2017-11-11)
4
8
 
5
9
  * Support nested attributes.
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vue-rails-form-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tsutomu KURODA