active_fields 2.0.1 → 3.0.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/.rubocop.yml +15 -2
- data/Appraisals +19 -0
- data/CHANGELOG.md +9 -1
- data/README.md +202 -26
- data/Rakefile +0 -2
- data/app/models/concerns/active_fields/customizable_concern.rb +66 -14
- data/app/models/concerns/active_fields/field_concern.rb +38 -4
- data/app/models/concerns/active_fields/value_concern.rb +8 -1
- data/db/migrate/20250229230000_add_scope_to_active_fields.rb +14 -0
- data/gemfiles/rails_7.1.gemfile +15 -0
- data/gemfiles/rails_7.2.gemfile +15 -0
- data/gemfiles/rails_8.0.gemfile +15 -0
- data/gemfiles/rails_8.1.gemfile +15 -0
- data/lib/active_fields/casters/date_array_caster.rb +2 -2
- data/lib/active_fields/casters/date_time_array_caster.rb +2 -2
- data/lib/active_fields/casters/decimal_array_caster.rb +2 -2
- data/lib/active_fields/casters/enum_array_caster.rb +2 -2
- data/lib/active_fields/casters/integer_array_caster.rb +2 -2
- data/lib/active_fields/casters/text_array_caster.rb +2 -2
- data/lib/active_fields/config.rb +2 -2
- data/lib/active_fields/finders/array_finder.rb +8 -2
- data/lib/active_fields/has_active_fields.rb +3 -1
- data/lib/active_fields/version.rb +1 -1
- data/lib/generators/active_fields/scaffold/templates/controllers/active_fields_controller.rb +18 -18
- data/lib/generators/active_fields/scaffold/templates/javascript/controllers/active_field_form_controller.js +19 -0
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_boolean.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_date.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_date_array.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_datetime.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_datetime_array.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_decimal.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_decimal_array.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_enum.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_enum_array.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_integer.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_integer_array.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_text.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_text_array.html.erb +22 -1
- data/lib/generators/active_fields/scaffold/templates/views/active_fields/index.html.erb +2 -0
- metadata +24 -4
- data/CODE_OF_CONDUCT.md +0 -84
|
@@ -12,15 +12,22 @@ module ActiveFields
|
|
|
12
12
|
inverse_of: :active_field,
|
|
13
13
|
dependent: :destroy
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
# Returns active fields for the given customizable type, including both
|
|
16
|
+
# scoped fields (when scope parameter is provided) and global fields (where scope is nil).
|
|
17
|
+
scope :for, ->(customizable_type, scope: nil) do
|
|
18
|
+
# Global fields are available to all records of the given customizable type.
|
|
19
|
+
scopes = [scope, nil].uniq
|
|
20
|
+
where(customizable_type: customizable_type, scope: scopes)
|
|
21
|
+
end
|
|
16
22
|
|
|
17
23
|
validates :type, presence: true
|
|
18
|
-
validates :name, presence: true
|
|
19
|
-
|
|
24
|
+
validates :name, presence: true
|
|
25
|
+
validate :validate_name_uniqueness
|
|
20
26
|
validate :validate_default_value
|
|
21
27
|
validate :validate_customizable_model_allows_type
|
|
22
28
|
|
|
23
29
|
after_initialize :set_defaults
|
|
30
|
+
before_validation :set_scope
|
|
24
31
|
end
|
|
25
32
|
|
|
26
33
|
class_methods do
|
|
@@ -89,7 +96,7 @@ module ActiveFields
|
|
|
89
96
|
|
|
90
97
|
# Returns customizable types that allow this field type.
|
|
91
98
|
#
|
|
92
|
-
#
|
|
99
|
+
# NOTE:
|
|
93
100
|
# - The customizable model must be loaded to appear in this list.
|
|
94
101
|
# Relationships between customizable models and field types are established in the `has_active_fields` method,
|
|
95
102
|
# which is typically called within the customizable model.
|
|
@@ -104,6 +111,26 @@ module ActiveFields
|
|
|
104
111
|
|
|
105
112
|
private
|
|
106
113
|
|
|
114
|
+
# NOTE: The uniqueness constraint in the DB does not fully enforce this validation:
|
|
115
|
+
# Records where scope is NULL do not prevent the existence of records with the same
|
|
116
|
+
# [name, customizable_type] but with a non-NULL scope, and vice versa.
|
|
117
|
+
def validate_name_uniqueness
|
|
118
|
+
base_scope =
|
|
119
|
+
ActiveFields.config.field_base_class.excluding(self).where(customizable_type: customizable_type, name: name)
|
|
120
|
+
|
|
121
|
+
if scope.nil?
|
|
122
|
+
if base_scope.exists?
|
|
123
|
+
errors.add(:name, :taken)
|
|
124
|
+
return false
|
|
125
|
+
end
|
|
126
|
+
elsif base_scope.exists?(scope: [scope, nil])
|
|
127
|
+
errors.add(:name, :taken)
|
|
128
|
+
return false
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
true
|
|
132
|
+
end
|
|
133
|
+
|
|
107
134
|
def validate_default_value
|
|
108
135
|
validator = value_validator
|
|
109
136
|
return if validator.validate(default_value)
|
|
@@ -128,5 +155,12 @@ module ActiveFields
|
|
|
128
155
|
end
|
|
129
156
|
|
|
130
157
|
def set_defaults; end
|
|
158
|
+
|
|
159
|
+
# Forces scope to nil if the customizable model does not have a scope method.
|
|
160
|
+
def set_scope
|
|
161
|
+
return if customizable_model.nil?
|
|
162
|
+
|
|
163
|
+
self.scope = nil if customizable_model.active_fields_scope_method.nil?
|
|
164
|
+
end
|
|
131
165
|
end
|
|
132
166
|
end
|
|
@@ -59,7 +59,14 @@ module ActiveFields
|
|
|
59
59
|
|
|
60
60
|
def validate_customizable_allowed
|
|
61
61
|
return true if active_field.nil?
|
|
62
|
-
|
|
62
|
+
|
|
63
|
+
if customizable_type != active_field.customizable_type
|
|
64
|
+
errors.add(:customizable, :invalid)
|
|
65
|
+
return false
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
return true if active_field.scope.nil?
|
|
69
|
+
return true if customizable&.active_fields_scope == active_field.scope
|
|
63
70
|
|
|
64
71
|
errors.add(:customizable, :invalid)
|
|
65
72
|
false
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AddScopeToActiveFields < ActiveRecord::Migration[7.1]
|
|
4
|
+
def change
|
|
5
|
+
change_table :active_fields do |t|
|
|
6
|
+
t.string :scope
|
|
7
|
+
|
|
8
|
+
t.remove_index %i[name customizable_type], unique: true
|
|
9
|
+
t.remove_index :customizable_type
|
|
10
|
+
|
|
11
|
+
t.index %i[customizable_type scope name], unique: true, nulls_not_distinct: true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "puma"
|
|
6
|
+
gem "propshaft"
|
|
7
|
+
gem "importmap-rails"
|
|
8
|
+
gem "stimulus-rails"
|
|
9
|
+
gem "rails", "~> 7.1.0"
|
|
10
|
+
|
|
11
|
+
group :development do
|
|
12
|
+
gem "web-console"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
gemspec path: "../"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "puma"
|
|
6
|
+
gem "propshaft"
|
|
7
|
+
gem "importmap-rails"
|
|
8
|
+
gem "stimulus-rails"
|
|
9
|
+
gem "rails", "~> 7.2.0"
|
|
10
|
+
|
|
11
|
+
group :development do
|
|
12
|
+
gem "web-console"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
gemspec path: "../"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "puma"
|
|
6
|
+
gem "propshaft"
|
|
7
|
+
gem "importmap-rails"
|
|
8
|
+
gem "stimulus-rails"
|
|
9
|
+
gem "rails", "~> 8.0.0"
|
|
10
|
+
|
|
11
|
+
group :development do
|
|
12
|
+
gem "web-console"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
gemspec path: "../"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "puma"
|
|
6
|
+
gem "propshaft"
|
|
7
|
+
gem "importmap-rails"
|
|
8
|
+
gem "stimulus-rails"
|
|
9
|
+
gem "rails", "~> 8.1.0"
|
|
10
|
+
|
|
11
|
+
group :development do
|
|
12
|
+
gem "web-console"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
gemspec path: "../"
|
|
@@ -6,13 +6,13 @@ module ActiveFields
|
|
|
6
6
|
def serialize(value)
|
|
7
7
|
return unless value.is_a?(Array)
|
|
8
8
|
|
|
9
|
-
value.map { super(
|
|
9
|
+
value.map { |element| super(element) }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def deserialize(value)
|
|
13
13
|
return unless value.is_a?(Array)
|
|
14
14
|
|
|
15
|
-
value.map { super(
|
|
15
|
+
value.map { |element| super(element) }
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -6,13 +6,13 @@ module ActiveFields
|
|
|
6
6
|
def serialize(value)
|
|
7
7
|
return unless value.is_a?(Array)
|
|
8
8
|
|
|
9
|
-
value.map { super(
|
|
9
|
+
value.map { |element| super(element) }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def deserialize(value)
|
|
13
13
|
return unless value.is_a?(Array)
|
|
14
14
|
|
|
15
|
-
value.map { super(
|
|
15
|
+
value.map { |element| super(element) }
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -6,13 +6,13 @@ module ActiveFields
|
|
|
6
6
|
def serialize(value)
|
|
7
7
|
return unless value.is_a?(Array)
|
|
8
8
|
|
|
9
|
-
value.map { super(
|
|
9
|
+
value.map { |element| super(element) }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def deserialize(value)
|
|
13
13
|
return unless value.is_a?(Array)
|
|
14
14
|
|
|
15
|
-
value.map { super(
|
|
15
|
+
value.map { |element| super(element) }
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -6,13 +6,13 @@ module ActiveFields
|
|
|
6
6
|
def serialize(value)
|
|
7
7
|
return unless value.is_a?(Array)
|
|
8
8
|
|
|
9
|
-
value.map { super(
|
|
9
|
+
value.map { |element| super(element) }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def deserialize(value)
|
|
13
13
|
return unless value.is_a?(Array)
|
|
14
14
|
|
|
15
|
-
value.map { super(
|
|
15
|
+
value.map { |element| super(element) }
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -6,13 +6,13 @@ module ActiveFields
|
|
|
6
6
|
def serialize(value)
|
|
7
7
|
return unless value.is_a?(Array)
|
|
8
8
|
|
|
9
|
-
value.map { super(
|
|
9
|
+
value.map { |element| super(element) }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def deserialize(value)
|
|
13
13
|
return unless value.is_a?(Array)
|
|
14
14
|
|
|
15
|
-
value.map { super(
|
|
15
|
+
value.map { |element| super(element) }
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -6,13 +6,13 @@ module ActiveFields
|
|
|
6
6
|
def serialize(value)
|
|
7
7
|
return unless value.is_a?(Array)
|
|
8
8
|
|
|
9
|
-
value.map { super(
|
|
9
|
+
value.map { |element| super(element) }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def deserialize(value)
|
|
13
13
|
return unless value.is_a?(Array)
|
|
14
14
|
|
|
15
|
-
value.map { super(
|
|
15
|
+
value.map { |element| super(element) }
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
data/lib/active_fields/config.rb
CHANGED
|
@@ -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
|
-
[
|
|
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
|
-
[
|
|
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
|
data/lib/generators/active_fields/scaffold/templates/controllers/active_fields_controller.rb
CHANGED
|
@@ -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: :
|
|
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: :
|
|
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
|
+
}
|
data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_boolean.html.erb
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
<%= form_with(
|
|
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? %>
|
data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_date.html.erb
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
<%= form_with(
|
|
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? %>
|
data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_date_array.html.erb
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
<%= form_with(
|
|
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? %>
|
data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_datetime.html.erb
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
<%= form_with(
|
|
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(
|
|
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? %>
|
data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_decimal.html.erb
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
<%= form_with(
|
|
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? %>
|