rondo_form 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c5d3d9c7c5df1095b20d8473c0e6e6307161cbf4c8b7a27aa7e43db9cdd6050
4
- data.tar.gz: 9aab5d1fff292c0e4c558aa3c37ef6954f52c82aeab2e8989e9751f744b29c7f
3
+ metadata.gz: 5f953e44cde6292d12ee7bd3042659c45de36770dfd6f81a4590452f309faa45
4
+ data.tar.gz: 5462a299afe097966aefbf5588ac8079dd35655e9cbd0389ddce5ef4d8978ba3
5
5
  SHA512:
6
- metadata.gz: 9494cd91916ad3ff074712e7d2b0c2acfa34ee425da35979f40a9fb5252269837589ae9eab8f802d68f7cb60fc2b9dc2e87001a9d16de6fde5152e59d0a5f39a
7
- data.tar.gz: 768eca8ff0a7ba31f9661ea51b53551d8a79cd2a13bc29c960ade8827e638be36e8675ad98502d0f772f7f71962d911aa6cc35be895dbfaa983e59d14dd0c864
6
+ metadata.gz: 8df5386a9afa39d992f3914e5f9ef7358aa2ca8fe41573e7ad56f7d87701f3c1c4d1202315d88fa1c581acf398148aa36c871f7b8c8855c54e17e040277e2175
7
+ data.tar.gz: 45e36511f96135582e1041153c3431600376943291138000023d0bd0de0965b7b0c0c024c679eb95f8e7d421504f66303ee4d324d6b1fe1f7d8ad6d2ebac9b3d
data/README.md CHANGED
@@ -10,7 +10,7 @@ Install the gem and add to the application's Gemfile by executing:
10
10
 
11
11
  Or inside the Gemfile add the following
12
12
 
13
- $ gem 'rondo_form', '~> 0.2.4'
13
+ $ gem 'rondo_form', '~> 0.2.5'
14
14
 
15
15
  Run the installation task:
16
16
 
@@ -63,10 +63,10 @@ In your `_task_fields` partial:
63
63
 
64
64
  ```
65
65
 
66
- _Note_:
67
- - Stimulus controller is `nested-rondo`, so you need to declare the element with `data-controller="nested-rondo"`.
68
- - You must add `data-nested-rondo-target="fieldContain"` to an element, that wraps all nested fields, the new field will be appended to this element.
69
- - `data-nested-rondo-field-class-value` is used to detect the element that needs to be removed. Its value must match the class name that wraps the partial. If you do not declare it, it will default remove the closest parent element.
66
+ _Convention_:
67
+ - For convention, I named Stimulus controller `nested-rondo`. But you can change the name of Javascript file and the value of `data-controller` to match your purpose.
68
+ - `data-nested-rondo-target="fieldContain"` must be added to an element that wraps all nested fields, the new field will be appended to this element.
69
+ - `data-nested-rondo-field-class-value` is used to detect the element that needs to be removed. Its value must match the class name of an element that wraps the partial. If you do not declare it, it will default remove the closest parent element.
70
70
 
71
71
  ## Contributing
72
72
 
@@ -7,8 +7,7 @@ export default class extends Controller {
7
7
  addField(e) {
8
8
  e.preventDefault();
9
9
 
10
- let assoc = e.target.dataset.association;
11
- let newField = this.buildNewAssociation(assoc);
10
+ const newField = this.buildNewAssociation(e);
12
11
  this.fieldContainTarget.insertAdjacentHTML("beforeend", newField);
13
12
  }
14
13
 
@@ -24,16 +23,19 @@ export default class extends Controller {
24
23
  }
25
24
  }
26
25
 
27
- buildNewAssociation(assoc) {
28
- let content = this.templateTarget.innerHTML;
29
- let regexpBraced = new RegExp('\\[new_' + assoc + '\\]', 'g');
26
+ buildNewAssociation(element) {
27
+ const assoc = element.target.dataset.association;
28
+ const assocs = element.target.dataset.associations;
29
+ const content = this.templateTarget.innerHTML;
30
+
31
+ let regexpBraced = new RegExp('\\[new_' + assoc + '\\](.*?\\s)', 'g');
30
32
  let newId = new Date().getTime();
31
- let newContent = content.replace(regexpBraced, '[' + newId + ']');
33
+ let newContent = content.replace(regexpBraced, '[' + newId + ']$1');
32
34
 
33
35
  if (newContent == content) {
34
36
  // assoc can be singular or plural
35
- regexpBraced = new RegExp('\\[new_' + assoc + 's\\]', 'g');
36
- newContent = content.replace(regexpBraced, '[' + newId + ']');
37
+ regexpBraced = new RegExp('\\[new_' + assocs + '\\](.*?\\s)', 'g');
38
+ newContent = content.replace(regexpBraced, '[' + newId + ']$1');
37
39
  }
38
40
  return newContent;
39
41
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RondoForm
4
- VERSION = "0.2.4"
4
+ VERSION = "0.2.5"
5
5
  end
@@ -48,6 +48,7 @@ module RondoForm
48
48
 
49
49
  html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
50
50
  html_options[:'data-association'] = association.to_s.singularize
51
+ html_options[:'data-associations'] = association.to_s.pluralize
51
52
  html_options[:'data-action'] = "click->nested-rondo#addField"
52
53
 
53
54
  new_object = f.object.class.reflect_on_association(association).klass.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rondo_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - hungle00
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-30 00:00:00.000000000 Z
11
+ date: 2024-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -89,7 +89,7 @@ licenses:
89
89
  metadata:
90
90
  homepage_uri: https://github.com/hungle00/rondo_form
91
91
  source_code_uri: https://github.com/hungle00/rondo_form
92
- post_install_message:
92
+ post_install_message:
93
93
  rdoc_options: []
94
94
  require_paths:
95
95
  - lib
@@ -104,8 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  requirements: []
107
- rubygems_version: 3.2.3
108
- signing_key:
107
+ rubygems_version: 3.4.10
108
+ signing_key:
109
109
  specification_version: 4
110
110
  summary: Cocoon, but with Stimulus JS
111
111
  test_files: []