base_editing_bootstrap 1.13.0 → 1.14.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
  SHA256:
3
- metadata.gz: 03c295a72d7902af261c7c01405cc45a7b81d243c846f60c1974f4e07e5e648e
4
- data.tar.gz: 5281b24d0df35c81db386217c763e266bf29affa07ca33c34632527981f5be5b
3
+ metadata.gz: 74db6610e2c8ab5c7f25de60eb6fb1c7ba1fa83570cd552a3356674356f02518
4
+ data.tar.gz: 8aea6970cecd4fa8623711b21d9ec77e2b2657757dfa94c91e94028b687a074e
5
5
  SHA512:
6
- metadata.gz: cdd4c188cef1aba14fadc79888e24fbdf3dafdbcc204ec933a1558ef5fbbed0255f36924c4e327c244e8176e777452077404a3c0c23b3ebeb1c869af62bf9ae3
7
- data.tar.gz: 74c856a196196dd319d42446c474d5ba5449cefb2d01a7333d3e20bc2b4bcbb1273777b01363381e52a0fc8abbdd9bc9249a8cd5da4cd8dc60d2e470408994f3
6
+ metadata.gz: 5713323d93896548db8ee7fd75b187e5b7b6b61efb76c3855a92c79139eaa993af1a480a6cc1fe85c84a95e9b8af1f2c0dabe615ce14815728450bbd4390b10e
7
+ data.tar.gz: 1a6068cc2a7b296c4f8d0a3a20097efd9dddb1752bb6e5e4844053ec8f6997eac49183af26d6873949c44d4bce05235ebfb655f171d7c0d2e203a48bef8988ae
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
  All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
3
3
 
4
4
  - - -
5
+ ## 1.14.0 - 2026-03-19
6
+ #### Features
7
+ - Nested elements with limit from rails config (#24) - (f003ce4) - Marino Bonetti
8
+ #### Bug Fixes
9
+ - Correct nested_form when elements are marked for destruction - (9fd6544) - Marino Bonetti
10
+
11
+ - - -
12
+
5
13
  ## 1.13.0 - 2026-02-03
6
14
  #### Features
7
15
  - Form submit button inheritance value - (00b04b1) - Marino Bonetti
data/README.md CHANGED
@@ -35,16 +35,34 @@ $ bundle exec rails g base_editing_bootstrap:install
35
35
 
36
36
  **Si presume quindi che ActiveStorage sia correttamente installato, completo del javascript per il direct upload**
37
37
 
38
+ ### Upgrade Notes
39
+ - From <= 1.13:
40
+ In `app/javascript/controllers/application.js` replace:
41
+ ```js
42
+ import RailsNestedForm from '@stimulus-components/rails-nested-form'
43
+ application.register('nested-form', RailsNestedForm)
44
+ ```
45
+ with:
46
+ ```js
47
+ import NestedForm from 'nested_form_controller';
48
+ application.register('nested-form', NestedForm);
49
+ ```
50
+ in `config/importmap.rb` remove:
51
+ ```ruby
52
+ pin "@stimulus-components/rails-nested-form"
53
+ ```
54
+ and finaly remove in vendor/javascript the `@stimulus-components/rails-nested-form` downloaded dependencies
55
+
38
56
  ### Note for NestedAttributes
39
57
 
40
- Seguire le istruzioni per installare anche NestedAttributeForm Controller per stimulus:
58
+ Il controller nested attributes viene importato da importmaps dell'engine.
59
+ E' necessagio registrare il nuovo controller in app/javascript/application.js
41
60
 
42
- ```shell
43
- bin/importmap pin @stimulus-components/rails-nested-form
61
+ ```js
62
+ import NestedForm from 'nested_form_controller'; // Mappato con import maps locale
63
+ application.register('nested-form', NestedForm); // Utilizzato nell'interfaccia della form.
44
64
  ```
45
65
 
46
- e seguire installazione https://www.stimulus-components.com/docs/stimulus-rails-nested-form
47
-
48
66
  ### Generators
49
67
 
50
68
  Then Install dependency (if you run base_editing_bootstrap:install you are good to go):
@@ -0,0 +1 @@
1
+ //= link nested_form_controller.js
@@ -0,0 +1,48 @@
1
+ import NestedForm from "@stimulus-components/rails-nested-form"
2
+
3
+ // Connects to data-controller="nested-form"
4
+ export default class extends NestedForm {
5
+
6
+ static values = {
7
+ limit: Number,
8
+ }
9
+
10
+ add(e) {
11
+ super.add(e);
12
+ this.check_for_enabling_add_button(e);
13
+ }
14
+
15
+ remove(e) {
16
+ super.remove(e);
17
+ this.check_for_enabling_add_button(e);
18
+ }
19
+
20
+ // Elenco elementi presenti visibili (e quindi non settati per essere cancellati)
21
+ total_active_elements() {
22
+ let count = 0;
23
+
24
+ this.targetTarget.parentElement.querySelectorAll(this.wrapperSelectorValue).forEach((ele) => {
25
+ if (ele.checkVisibility()) {
26
+ count += 1;
27
+ }
28
+ })
29
+ return count;
30
+ }
31
+
32
+ check_for_enabling_add_button(e) {
33
+ if (this.hasLimitValue) {
34
+ if (this.total_active_elements() >= this.limitValue) {
35
+ // Aggiungiamo classe disable sull'elemento che ha lanciato questo evento
36
+ this.add_button().disabled = "disabled";
37
+ } else {
38
+ this.add_button().removeAttribute("disabled");
39
+ }
40
+ }
41
+ }
42
+
43
+ add_button() {
44
+ return this.element.querySelector('[data-action="nested-form#add"]')
45
+ }
46
+
47
+
48
+ }
@@ -1,4 +1,4 @@
1
- <tr class="nested-form-wrapper" data-new-record="<%= form.object.new_record? %>" id="<%= dom_id(form.object) %>">
1
+ <tr class="nested-form-wrapper <%= (form.object.marked_for_destruction? ? "d-none" : "") %>" data-new-record="<%= form.object.new_record? %>" id="<%= dom_id(form.object) %>">
2
2
 
3
3
  <% policy(form.object).editable_attributes.each do |field| %>
4
4
  <td>
@@ -1,5 +1,25 @@
1
1
  <%# locals: (form:, field:,new_object:) -%>
2
- <%= content_tag :table, class: "table", data: {controller: 'nested-form'} do %>
2
+ <%
3
+
4
+ ##
5
+ # Costruisco le opzioni per limitare tramite interfaccia (ricevuta da configurazione di Rails nested_attributes_for)
6
+ # il numero di nested elements
7
+ controller_data = {controller: 'nested-form'}
8
+ if (limit = form.object.class.nested_attributes_options[field].dig(:limit))
9
+ controller_data["nested-form-limit-value"] = \
10
+ case limit
11
+ when Symbol #TODO add tests
12
+ form.object.class.send(limit)
13
+ when Proc #TODO add tests
14
+ limit.call
15
+ else
16
+ limit
17
+ end
18
+ end
19
+
20
+ %>
21
+
22
+ <%= content_tag :table, class: "table", data: controller_data do %>
3
23
 
4
24
  <thead>
5
25
  <tr>
@@ -0,0 +1,2 @@
1
+ pin "@stimulus-components/rails-nested-form", to: "https://ga.jspm.io/npm:@stimulus-components/rails-nested-form@5.0.0/dist/stimulus-rails-nested-form.mjs" # @5.0.0
2
+ pin_all_from File.expand_path("../app/assets/javascripts", __dir__)
@@ -1 +1 @@
1
- 1.13.0
1
+ 1.14.0
@@ -5,5 +5,13 @@ module BaseEditingBootstrap
5
5
  app.deprecators[:base_editing_bootstrap] = BaseEditingBootstrap.deprecator
6
6
  end
7
7
 
8
+ initializer "base_editing_bootstrap.importmap", before: "importmap" do |app|
9
+ app.config.importmap.paths << Engine.root.join("config/importmap.rb")
10
+ end
11
+
12
+ initializer "base_editing_bootstrap.assets.precompile" do |app|
13
+ app.config.assets.precompile << "nested_form_controller.js"
14
+ end
15
+
8
16
  end
9
17
  end
@@ -35,9 +35,9 @@ module BaseEditingBootstrap
35
35
  # attualmente penso sia più sensato semplicemente scrivere a video i passaggi necessari, dato che
36
36
  # potrebbe essere già presente importmap, nested_attribute_controller e le varie configurazioni
37
37
 
38
- say "Install dependencies for nested attributes:"
39
- say " bin/importmap pin @stimulus-components/rails-nested-form"
40
- say "Attiva quindi come spiegato qua: https://www.stimulus-components.com/docs/stimulus-rails-nested-form il controller"
38
+ say "Install nested attributes controller, add to application.js:"
39
+ say " import NestedForm from 'nested_form_controller' \n
40
+ application.register('nested-form', NestedForm)"
41
41
 
42
42
  end
43
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: base_editing_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marino Bonetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-03 00:00:00.000000000 Z
11
+ date: 2026-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -320,6 +320,7 @@ files:
320
320
  - README.md
321
321
  - Rakefile
322
322
  - app/assets/config/base_editing_bootstrap_manifest.js
323
+ - app/assets/javascripts/nested_form_controller.js
323
324
  - app/controllers/.keep
324
325
  - app/controllers/base_editing_controller.rb
325
326
  - app/controllers/restricted_area_controller.rb
@@ -389,6 +390,7 @@ files:
389
390
  - app/views/kaminari/_paginator.html.erb
390
391
  - app/views/kaminari/_prev_page.html.erb
391
392
  - base_editing_bootstrap.gemspec
393
+ - config/importmap.rb
392
394
  - config/initializers/base_field_error_proc.rb
393
395
  - config/locales/it.yml
394
396
  - config/routes.rb