active_fields 2.0.1 → 3.0.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -2
  3. data/Appraisals +19 -0
  4. data/CHANGELOG.md +6 -1
  5. data/README.md +113 -12
  6. data/Rakefile +0 -2
  7. data/app/models/concerns/active_fields/customizable_concern.rb +59 -11
  8. data/app/models/concerns/active_fields/field_concern.rb +38 -4
  9. data/app/models/concerns/active_fields/value_concern.rb +8 -1
  10. data/db/migrate/20250229230000_add_scope_to_active_fields.rb +14 -0
  11. data/gemfiles/rails_7.1.gemfile +15 -0
  12. data/gemfiles/rails_7.2.gemfile +15 -0
  13. data/gemfiles/rails_8.0.gemfile +15 -0
  14. data/gemfiles/rails_8.1.gemfile +15 -0
  15. data/lib/active_fields/casters/date_array_caster.rb +2 -2
  16. data/lib/active_fields/casters/date_time_array_caster.rb +2 -2
  17. data/lib/active_fields/casters/decimal_array_caster.rb +2 -2
  18. data/lib/active_fields/casters/enum_array_caster.rb +2 -2
  19. data/lib/active_fields/casters/integer_array_caster.rb +2 -2
  20. data/lib/active_fields/casters/text_array_caster.rb +2 -2
  21. data/lib/active_fields/config.rb +2 -2
  22. data/lib/active_fields/finders/array_finder.rb +8 -2
  23. data/lib/active_fields/has_active_fields.rb +3 -1
  24. data/lib/active_fields/version.rb +1 -1
  25. data/lib/generators/active_fields/scaffold/templates/controllers/active_fields_controller.rb +18 -18
  26. data/lib/generators/active_fields/scaffold/templates/javascript/controllers/active_field_form_controller.js +19 -0
  27. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_boolean.html.erb +22 -1
  28. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_date.html.erb +22 -1
  29. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_date_array.html.erb +22 -1
  30. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_datetime.html.erb +22 -1
  31. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_datetime_array.html.erb +22 -1
  32. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_decimal.html.erb +22 -1
  33. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_decimal_array.html.erb +22 -1
  34. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_enum.html.erb +22 -1
  35. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_enum_array.html.erb +22 -1
  36. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_integer.html.erb +22 -1
  37. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_integer_array.html.erb +22 -1
  38. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_text.html.erb +22 -1
  39. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_text_array.html.erb +22 -1
  40. data/lib/generators/active_fields/scaffold/templates/views/active_fields/index.html.erb +2 -0
  41. metadata +24 -4
  42. data/CODE_OF_CONDUCT.md +0 -84
@@ -11,8 +11,6 @@ module ActiveFields
11
11
  attr_reader :fields
12
12
 
13
13
  def initialize
14
- @field_base_class_name = DEFAULT_FIELD_BASE_CLASS_NAME
15
- @value_class_name = DEFAULT_VALUE_CLASS_NAME
16
14
  @fields = {
17
15
  boolean: "ActiveFields::Field::Boolean",
18
16
  date: "ActiveFields::Field::Date",
@@ -28,6 +26,8 @@ module ActiveFields
28
26
  text: "ActiveFields::Field::Text",
29
27
  text_array: "ActiveFields::Field::TextArray",
30
28
  }
29
+ @field_base_class_name = DEFAULT_FIELD_BASE_CLASS_NAME
30
+ @value_class_name = DEFAULT_VALUE_CLASS_NAME
31
31
  end
32
32
 
33
33
  def field_base_class
@@ -91,7 +91,10 @@ module ActiveFields
91
91
  def jsonb_path_exists(target, jsonpath, vars = nil)
92
92
  Arel::Nodes::NamedFunction.new(
93
93
  "jsonb_path_exists",
94
- [target, *[jsonpath, vars&.to_json].compact.map { Arel::Nodes.build_quoted(_1) }],
94
+ [
95
+ target,
96
+ *[jsonpath, vars&.to_json].compact.map { |element| Arel::Nodes.build_quoted(element) },
97
+ ],
95
98
  )
96
99
  end
97
100
 
@@ -99,7 +102,10 @@ module ActiveFields
99
102
  def jsonb_path_query_array(target, jsonpath, vars = nil)
100
103
  Arel::Nodes::NamedFunction.new(
101
104
  "jsonb_path_query_array",
102
- [target, *[jsonpath, vars&.to_json].compact.map { Arel::Nodes.build_quoted(_1) }],
105
+ [
106
+ target,
107
+ *[jsonpath, vars&.to_json].compact.map { |element| Arel::Nodes.build_quoted(element) },
108
+ ],
103
109
  )
104
110
  end
105
111
 
@@ -6,12 +6,14 @@ module ActiveFields
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  class_methods do
9
- def has_active_fields(types: ActiveFields.config.type_names)
9
+ def has_active_fields(types: ActiveFields.config.type_names, scope_method: nil)
10
10
  include CustomizableConcern
11
11
 
12
12
  types.each do |field_type|
13
13
  ActiveFields.registry.add(field_type, name)
14
14
  end
15
+
16
+ define_singleton_method(:active_fields_scope_method) { scope_method }
15
17
  end
16
18
  end
17
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveFields
4
- VERSION = "2.0.1"
4
+ VERSION = "3.0.0"
5
5
  end
@@ -4,7 +4,7 @@ class ActiveFieldsController < ApplicationController
4
4
  before_action :set_active_field, only: %i[show edit update destroy]
5
5
 
6
6
  def index
7
- @active_fields = ActiveFields.config.field_base_class.order(:customizable_type, :id)
7
+ @active_fields = ActiveFields.config.field_base_class.order(:customizable_type, :scope, :id)
8
8
  end
9
9
 
10
10
  def show; end
@@ -13,23 +13,23 @@ class ActiveFieldsController < ApplicationController
13
13
  @active_field = model_class.new
14
14
  end
15
15
 
16
+ def edit; end
17
+
16
18
  def create
17
19
  @active_field = model_class.new(active_field_create_params(model_class))
18
20
 
19
21
  if @active_field.save
20
22
  redirect_to edit_active_field_path(@active_field), status: :see_other
21
23
  else
22
- render :new, status: :unprocessable_entity
24
+ render :new, status: :unprocessable_content
23
25
  end
24
26
  end
25
27
 
26
- def edit; end
27
-
28
28
  def update
29
29
  if @active_field.update(active_field_update_params(@active_field.class))
30
30
  redirect_to edit_active_field_path(@active_field), status: :see_other
31
31
  else
32
- render :edit, status: :unprocessable_entity
32
+ render :edit, status: :unprocessable_content
33
33
  end
34
34
  end
35
35
 
@@ -60,31 +60,31 @@ class ActiveFieldsController < ApplicationController
60
60
  # It is strongly recommended to move it to, for example, policies.
61
61
  def permitted_attributes_for_create(model_class)
62
62
  if model_class == ActiveFields::Field::Boolean
63
- %i[customizable_type name required nullable default_value]
63
+ %i[customizable_type name scope required nullable default_value]
64
64
  elsif model_class == ActiveFields::Field::Date
65
- %i[customizable_type name required min max default_value]
65
+ %i[customizable_type name scope required min max default_value]
66
66
  elsif model_class == ActiveFields::Field::DateArray
67
- [:customizable_type, :name, :min_size, :max_size, :min, :max, default_value: []]
67
+ [:customizable_type, :name, :scope, :min_size, :max_size, :min, :max, default_value: []]
68
68
  elsif model_class == ActiveFields::Field::DateTime
69
- %i[customizable_type name required min max precision default_value]
69
+ %i[customizable_type name scope required min max precision default_value]
70
70
  elsif model_class == ActiveFields::Field::DateTimeArray
71
- [:customizable_type, :name, :min_size, :max_size, :min, :max, :precision, default_value: []]
71
+ [:customizable_type, :name, :scope, :min_size, :max_size, :min, :max, :precision, default_value: []]
72
72
  elsif model_class == ActiveFields::Field::Decimal
73
- %i[customizable_type name required min max precision default_value]
73
+ %i[customizable_type name scope required min max precision default_value]
74
74
  elsif model_class == ActiveFields::Field::DecimalArray
75
- [:customizable_type, :name, :min_size, :max_size, :min, :max, :precision, default_value: []]
75
+ [:customizable_type, :name, :scope, :min_size, :max_size, :min, :max, :precision, default_value: []]
76
76
  elsif model_class == ActiveFields::Field::Enum
77
- [:customizable_type, :name, :required, :default_value, allowed_values: []]
77
+ [:customizable_type, :name, :scope, :required, :default_value, allowed_values: []]
78
78
  elsif model_class == ActiveFields::Field::EnumArray
79
- [:customizable_type, :name, :min_size, :max_size, allowed_values: [], default_value: []]
79
+ [:customizable_type, :name, :scope, :min_size, :max_size, allowed_values: [], default_value: []]
80
80
  elsif model_class == ActiveFields::Field::Integer
81
- %i[customizable_type name required min max default_value]
81
+ %i[customizable_type name scope required min max default_value]
82
82
  elsif model_class == ActiveFields::Field::IntegerArray
83
- [:customizable_type, :name, :min_size, :max_size, :min, :max, default_value: []]
83
+ [:customizable_type, :name, :scope, :min_size, :max_size, :min, :max, default_value: []]
84
84
  elsif model_class == ActiveFields::Field::Text
85
- %i[customizable_type name min_length max_length default_value]
85
+ %i[customizable_type name scope min_length max_length default_value]
86
86
  elsif model_class == ActiveFields::Field::TextArray
87
- [:customizable_type, :name, :min_size, :max_size, :min_length, :max_length, default_value: []]
87
+ [:customizable_type, :name, :scope, :min_size, :max_size, :min_length, :max_length, default_value: []]
88
88
  else
89
89
  raise ArgumentError, "undefined model_class `#{model_class.inspect}`"
90
90
  end
@@ -0,0 +1,19 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = [
5
+ "scopeInput",
6
+ "disableScopeInput",
7
+ ]
8
+
9
+ toggleScopeInput(e) {
10
+ e.preventDefault()
11
+
12
+ if (this.disableScopeInputTarget.checked) {
13
+ this.scopeInputTarget.disabled = true
14
+ this.scopeInputTarget.value = ""
15
+ } else {
16
+ this.scopeInputTarget.disabled = false
17
+ }
18
+ }
19
+ }
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :required %>
37
58
  <%= f.check_box :required, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :required %>
37
58
  <%= f.check_box :required, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :min_size %>
37
58
  <%= f.number_field :min_size, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :required %>
37
58
  <%= f.check_box :required, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :min_size %>
37
58
  <%= f.number_field :min_size, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :required %>
37
58
  <%= f.check_box :required, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :min_size %>
37
58
  <%= f.number_field :min_size, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :required %>
37
58
  <%= f.check_box :required, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :min_size %>
37
58
  <%= f.number_field :min_size, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :required %>
37
58
  <%= f.check_box :required, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :min_size %>
37
58
  <%= f.number_field :min_size, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :min_length %>
37
58
  <%= f.number_field :min_length, disabled: active_field.persisted? %>
@@ -1,4 +1,9 @@
1
- <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
1
+ <%= form_with(
2
+ model: active_field,
3
+ scope: :active_field,
4
+ url: active_field.persisted? ? active_field_path(active_field) : active_fields_path,
5
+ data: { controller: "active-field-form" }
6
+ ) do |f| %>
2
7
  <% if active_field.errors.any? %>
3
8
  <div style="color: red">
4
9
  <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
@@ -32,6 +37,22 @@
32
37
  <%= f.text_field :name %>
33
38
  </div>
34
39
 
40
+ <% if active_field.persisted? %>
41
+ <% if active_field.scope %>
42
+ <div>
43
+ <%= f.label :scope %>
44
+ <%= f.text_field :scope, disabled: true %>
45
+ </div>
46
+ <% end %>
47
+ <% else %>
48
+ <div>
49
+ <%= f.label :scope %>
50
+ <%= f.text_field :scope, data: { "active-field-form-target": "scopeInput" } %>
51
+ <%= f.label :disable_scope %>
52
+ <%= f.check_box :disable_scope, data: { "active-field-form-target": "disableScopeInput", "action": "change->active-field-form#toggleScopeInput" } %>
53
+ </div>
54
+ <% end %>
55
+
35
56
  <div>
36
57
  <%= f.label :min_size %>
37
58
  <%= f.number_field :min_size, disabled: active_field.persisted? %>
@@ -19,6 +19,7 @@
19
19
  <th>Type</th>
20
20
  <th>Customizable type</th>
21
21
  <th>Name</th>
22
+ <th>Scope</th>
22
23
  <th>Options</th>
23
24
  <th>Default value</th>
24
25
  <th></th>
@@ -32,6 +33,7 @@
32
33
  <td><%= active_field.type_name %></td>
33
34
  <td><%= active_field.customizable_type %></td>
34
35
  <td><%= active_field.name %></td>
36
+ <td><code><%= active_field.scope.inspect %></code></td>
35
37
  <td><code><%= active_field.options %></code></td>
36
38
  <td><code><%= active_field.default_value.inspect %></code></td>
37
39
  <td><%= button_to "Destroy", active_field_path(active_field), method: :delete %></td>