phlexi-form 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/phlexi/form/base.rb +15 -5
- data/lib/phlexi/form/builder.rb +9 -1
- data/lib/phlexi/form/components/concerns/uploads_file.rb +12 -0
- data/lib/phlexi/form/components/file_input.rb +2 -0
- data/lib/phlexi/form/structure/manages_fields.rb +25 -0
- data/lib/phlexi/form/structure/namespace.rb +2 -0
- data/lib/phlexi/form/structure/namespace_collection.rb +2 -0
- data/lib/phlexi/form/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6b1a5926f08261bf0fa3c607395ddd570c52417636f559b7f11a87a46e8c06d
|
4
|
+
data.tar.gz: ca036dc0035a0161fe4a0411dddbff11d7b1edea529b266ac3b29b1caded91e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94a54baa5507d3309efbf06dc8aa230ec8814be37fe7a99e72b294c9d3ed0528e90ea5f782b1333179a5fef8b3b244355b22f38b8bd4d98a661d40440adc52ad
|
7
|
+
data.tar.gz: bea9112fe8131a517381b1a2d4715b266b09fe82a608e96495366e43d4a565ae0bd60296e455118ad515ea41d795e49218a917367dcd3c7478fc88d2ce0cd1da
|
data/lib/phlexi/form/base.rb
CHANGED
@@ -34,7 +34,7 @@ module Phlexi
|
|
34
34
|
|
35
35
|
attr_reader :key, :object
|
36
36
|
|
37
|
-
delegate :field, :submit_button, :nest_one, :nest_many, to: :@namespace
|
37
|
+
delegate :field, :submit_button, :nest_one, :nest_many, :has_file_input?, to: :@namespace
|
38
38
|
|
39
39
|
# Initializes a new Form instance.
|
40
40
|
#
|
@@ -65,10 +65,18 @@ module Phlexi
|
|
65
65
|
#
|
66
66
|
# @return [void]
|
67
67
|
def view_template(&)
|
68
|
-
|
68
|
+
captured = capture { form_template(&) }
|
69
|
+
form_tag do
|
69
70
|
form_errors
|
70
|
-
|
71
|
-
|
71
|
+
plain(captured)
|
72
|
+
end
|
73
|
+
|
74
|
+
# TODO: phlex v2
|
75
|
+
# captured = capture { form_template(&) }
|
76
|
+
# form_tag do
|
77
|
+
# form_errors
|
78
|
+
# raw(safe(captured))
|
79
|
+
# end
|
72
80
|
end
|
73
81
|
|
74
82
|
def form_errors
|
@@ -254,12 +262,14 @@ module Phlexi
|
|
254
262
|
#
|
255
263
|
# @return [Hash] The form attributes
|
256
264
|
def form_attributes
|
257
|
-
mix({
|
265
|
+
attrs = mix({
|
258
266
|
id: @namespace.dom_id,
|
259
267
|
class: form_class,
|
260
268
|
action: form_action,
|
261
269
|
method: standardized_form_method
|
262
270
|
}, attributes)
|
271
|
+
attrs[:enctype] ||= "multipart/form-data" if has_file_input?
|
272
|
+
attrs
|
263
273
|
end
|
264
274
|
|
265
275
|
# Renders the authenticity token if required.
|
data/lib/phlexi/form/builder.rb
CHANGED
@@ -249,10 +249,17 @@ module Phlexi
|
|
249
249
|
@field_input_extractor.extract_input(params)
|
250
250
|
end
|
251
251
|
|
252
|
+
def has_file_input!
|
253
|
+
parent.has_file_input!
|
254
|
+
end
|
255
|
+
|
252
256
|
protected
|
253
257
|
|
254
258
|
def create_component(component_class, theme_key, **attributes, &)
|
255
259
|
theme_attributes = apply_component_theme(attributes, theme_key)
|
260
|
+
# TODO: refactor all this type checking code such that, the concerns will perform these actions.
|
261
|
+
# Basically, invert control so that the component asks for the extra attributes
|
262
|
+
# or calls #has_file_input!
|
256
263
|
extra_attributes = if component_class.include?(Phlexi::Form::Components::Concerns::HandlesInput)
|
257
264
|
input_attributes
|
258
265
|
else
|
@@ -260,10 +267,11 @@ module Phlexi
|
|
260
267
|
end
|
261
268
|
attributes = mix(theme_attributes, extra_attributes, attributes)
|
262
269
|
component = component_class.new(self, **attributes, &)
|
263
|
-
if component_class.include?(Components::Concerns::ExtractsInput)
|
270
|
+
if component_class.include?(Components::Concerns::ExtractsInput)
|
264
271
|
raise "input component already defined: #{@field_input_extractor.inspect}" if @field_input_extractor
|
265
272
|
|
266
273
|
@field_input_extractor = component
|
274
|
+
has_file_input! if component_class.include?(Components::Concerns::UploadsFile)
|
267
275
|
end
|
268
276
|
|
269
277
|
component
|
@@ -4,6 +4,8 @@ module Phlexi
|
|
4
4
|
module Form
|
5
5
|
module Components
|
6
6
|
class FileInput < Input
|
7
|
+
include Phlexi::Form::Components::Concerns::UploadsFile
|
8
|
+
|
7
9
|
def view_template
|
8
10
|
input(type: :hidden, name: attributes[:name], value: "", autocomplete: "off", hidden: true) if include_hidden?
|
9
11
|
input(**attributes)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlexi
|
4
|
+
module Form
|
5
|
+
module Structure
|
6
|
+
module ManagesFields
|
7
|
+
def has_file_input!
|
8
|
+
if parent
|
9
|
+
parent.has_file_input!
|
10
|
+
else
|
11
|
+
@has_file_input = true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_file_input?
|
16
|
+
if parent
|
17
|
+
parent.has_file_input?
|
18
|
+
else
|
19
|
+
@has_file_input || false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -4,6 +4,8 @@ module Phlexi
|
|
4
4
|
module Form
|
5
5
|
module Structure
|
6
6
|
class Namespace < Phlexi::Field::Structure::Namespace
|
7
|
+
include Phlexi::Form::Structure::ManagesFields
|
8
|
+
|
7
9
|
class NamespaceCollection < Phlexi::Form::Structure::NamespaceCollection; end
|
8
10
|
|
9
11
|
def submit_button(key = :submit_button, **, &)
|
data/lib/phlexi/form/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phlexi-form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Froelich
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- lib/phlexi/form/components/concerns/handles_array_input.rb
|
216
216
|
- lib/phlexi/form/components/concerns/handles_input.rb
|
217
217
|
- lib/phlexi/form/components/concerns/submits_form.rb
|
218
|
+
- lib/phlexi/form/components/concerns/uploads_file.rb
|
218
219
|
- lib/phlexi/form/components/error.rb
|
219
220
|
- lib/phlexi/form/components/file_input.rb
|
220
221
|
- lib/phlexi/form/components/form_errors.rb
|
@@ -245,6 +246,7 @@ files:
|
|
245
246
|
- lib/phlexi/form/options/step.rb
|
246
247
|
- lib/phlexi/form/options/validators.rb
|
247
248
|
- lib/phlexi/form/structure/field_collection.rb
|
249
|
+
- lib/phlexi/form/structure/manages_fields.rb
|
248
250
|
- lib/phlexi/form/structure/namespace.rb
|
249
251
|
- lib/phlexi/form/structure/namespace_collection.rb
|
250
252
|
- lib/phlexi/form/theme.rb
|