vanilla_nested 1.6.2 → 1.7.1
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 +4 -4
- data/app/assets/javascripts/vanilla_nested.js +17 -5
- data/lib/vanilla_nested/view_helpers.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac7c63dd72d8c42d48ab71efde141c98ec65a465cfd8323e0e5f447ecc7ebfd9
|
4
|
+
data.tar.gz: 2a3b4ca86838840ae7d82f85627e6227f2e45023b81e274ecc1b2dd3ec882514
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9053d7029a45a74074f441d525ba98abc262e4d818ee2f226686bdf1842287835fedd1c620fd3f7991d817c1ea8cac60757fc803a6c0109a36c40de05bdff7b1
|
7
|
+
data.tar.gz: 50b6c9cc47231d7bb69804797a46870c1ad8c4293a3718b95b999007139253bd6bb5304b662ccb14e5851a2514ed41712735b9913bff1555cb8fefe166a47c09
|
@@ -63,6 +63,7 @@
|
|
63
63
|
if (wrapper.classList.contains('added-by-vanilla-nested')) {
|
64
64
|
wrapper.remove();
|
65
65
|
} else {
|
66
|
+
wrapper.classList.add('removed-by-vanilla-nested');
|
66
67
|
const destroyInput = wrapper.querySelector('[name$="[_destroy]"');
|
67
68
|
wrapper.innerHTML = '';
|
68
69
|
wrapper.insertAdjacentElement('afterbegin', destroyInput);
|
@@ -85,6 +86,7 @@
|
|
85
86
|
// "wrapper" is the wrapper to hide
|
86
87
|
// "element" is the link to remove the wrapper
|
87
88
|
function hideFieldsWithUndo(wrapper, element) {
|
89
|
+
wrapper.classList.add('hidden-by-vanilla-nested');
|
88
90
|
[...wrapper.children].forEach(child => {
|
89
91
|
// store original style for after undo
|
90
92
|
if (child.getAttribute("style")) {
|
@@ -104,6 +106,7 @@
|
|
104
106
|
clearTimeout(timer);
|
105
107
|
unhideFields(wrapper);
|
106
108
|
wrapper.querySelector('[name$="[_destroy]"]').value = '0';
|
109
|
+
wrapper.classList.remove('hidden-by-vanilla-nested');
|
107
110
|
_dispatchEvent(wrapper, 'vanilla-nested:fields-hidden-undo', undoLink);
|
108
111
|
undoLink.remove();
|
109
112
|
}
|
@@ -113,6 +116,7 @@
|
|
113
116
|
// start the timer
|
114
117
|
const _onTimerCompleted = function() {
|
115
118
|
hideWrapper(wrapper);
|
119
|
+
wrapper.classList.remove('hidden-by-vanilla-nested');
|
116
120
|
unhideFields(wrapper);
|
117
121
|
_dispatchEvent(wrapper, 'vanilla-nested:fields-removed', undoLink);
|
118
122
|
undoLink.remove();
|
@@ -167,11 +171,19 @@
|
|
167
171
|
})
|
168
172
|
}
|
169
173
|
|
170
|
-
let vanillaNestedInitialized = false
|
171
|
-
|
174
|
+
let vanillaNestedInitialized = false
|
175
|
+
const initOnce = () => {
|
172
176
|
if (!vanillaNestedInitialized) {
|
173
|
-
vanillaNestedInitialized = true
|
174
|
-
initVanillaNested()
|
177
|
+
vanillaNestedInitialized = true
|
178
|
+
initVanillaNested()
|
175
179
|
}
|
176
|
-
}
|
180
|
+
}
|
181
|
+
|
182
|
+
if (["complete", "interactive"].includes(document.readyState)) {
|
183
|
+
// if DOMContentLoaded was already fired
|
184
|
+
initOnce()
|
185
|
+
} else {
|
186
|
+
// else wait for it
|
187
|
+
document.addEventListener("DOMContentLoaded", () => initOnce())
|
188
|
+
}
|
177
189
|
})()
|
@@ -9,11 +9,12 @@ module VanillaNested
|
|
9
9
|
# @param link_classes [String] space separated classes for the link tag
|
10
10
|
# @param insert_method [:append, :prepend] tells javascript if the new fields should be appended or prepended to the container
|
11
11
|
# @param partial_form_variable [String, Symbol] name of the variable that represents the form builder inside the fields partial
|
12
|
+
# @param partial_locals [Hash] extra params that should be send to the partial
|
12
13
|
# @param tag [String] HTML tag to use for the html generated, defaults to and `a` tag
|
13
14
|
# @param link_content [Block] block of code for the link content
|
14
15
|
# @param tag_attributes [Hash<attribute, value>] hash with attribute,value pairs for the html tag
|
15
16
|
# @return [String] link tag
|
16
|
-
def link_to_add_nested(form, association, container_selector, link_text: nil, link_classes: '', insert_method: :append, partial: nil, partial_form_variable: :form, tag: 'a', tag_attributes: {}, &link_content)
|
17
|
+
def link_to_add_nested(form, association, container_selector, link_text: nil, link_classes: '', insert_method: :append, partial: nil, partial_form_variable: :form, partial_locals: {}, tag: 'a', tag_attributes: {}, &link_content)
|
17
18
|
association_class = form.object.class.reflections[association.to_s].klass
|
18
19
|
object = association_class.new
|
19
20
|
|
@@ -21,7 +22,7 @@ module VanillaNested
|
|
21
22
|
|
22
23
|
html = capture do
|
23
24
|
form.fields_for association, object, child_index: '_idx_placeholder_' do |ff|
|
24
|
-
render partial: partial_name, locals: { partial_form_variable => ff }
|
25
|
+
render partial: partial_name, locals: { partial_form_variable => ff }.merge(partial_locals)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanilla_nested
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ariel Juodziukynas <arieljuod@gmail.com>
|
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
|
-
rubygems_version: 3.
|
41
|
+
rubygems_version: 3.4.6
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
44
|
summary: Dynamic nested forms using vanilla javascript
|