action_form 0.6.6 → 0.6.7
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/README.md +35 -7
- data/lib/action_form/base.rb +7 -0
- data/lib/action_form/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d9e95531741195220dd865f28be51b1787718ca2e30638d6bf56aa0407738318
|
|
4
|
+
data.tar.gz: 13711adfe6a993e256644a455cd30f43c711fcf4205d2c8ecbf21d614b927959
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aecaa123a9681d574d43af444d3ddaf5323c6c8b504af40f89cdefa8a462d60174b368c730d4041078d387442bc7cdfcaee1d48ee1b22bbcfe516ae11ab8a54e
|
|
7
|
+
data.tar.gz: cb795dabe51f9720690579a89568cfbe805fa7a43e93c51d8ed741501e63531eb3ee582c206009e07863390cbcc5583f0bc63f7f316e2fb1399aadb51bd46afd
|
data/README.md
CHANGED
|
@@ -692,9 +692,9 @@ class ProductForm < ActionForm::Base
|
|
|
692
692
|
end
|
|
693
693
|
```
|
|
694
694
|
|
|
695
|
-
#### **Custom
|
|
695
|
+
#### **Custom Owner Object**
|
|
696
696
|
|
|
697
|
-
You can pass a custom
|
|
697
|
+
You can pass a custom owner object when initializing a form, allowing you to separate form logic from business logic:
|
|
698
698
|
|
|
699
699
|
```ruby
|
|
700
700
|
class HostObject
|
|
@@ -1492,11 +1492,6 @@ Use `ActionForm::Rails::Base` instead of `ActionForm::Base` for Rails applicatio
|
|
|
1492
1492
|
class UserForm < ActionForm::Rails::Base
|
|
1493
1493
|
resource_model User
|
|
1494
1494
|
|
|
1495
|
-
element :name do
|
|
1496
|
-
input type: :text
|
|
1497
|
-
output type: :string, presence: true
|
|
1498
|
-
end
|
|
1499
|
-
|
|
1500
1495
|
element :email do
|
|
1501
1496
|
input type: :email
|
|
1502
1497
|
output type: :string, presence: true
|
|
@@ -1512,10 +1507,41 @@ class UserForm < ActionForm::Rails::Base
|
|
|
1512
1507
|
output type: :string
|
|
1513
1508
|
end
|
|
1514
1509
|
|
|
1510
|
+
subform :profile, default: {} do
|
|
1511
|
+
element :name do
|
|
1512
|
+
input(type: :text)
|
|
1513
|
+
output(type: :string)
|
|
1514
|
+
end
|
|
1515
|
+
|
|
1516
|
+
params do
|
|
1517
|
+
validates :name, presence: { if: :owner_check_profile_name? }
|
|
1518
|
+
end
|
|
1519
|
+
end
|
|
1520
|
+
|
|
1521
|
+
many :devices, default: [{}] do
|
|
1522
|
+
subform do
|
|
1523
|
+
element :name do
|
|
1524
|
+
input(type: :text)
|
|
1525
|
+
output(type: :string)
|
|
1526
|
+
end
|
|
1527
|
+
|
|
1528
|
+
params do
|
|
1529
|
+
validates :name, presence: { if: :owner_check_devices_name? }
|
|
1530
|
+
end
|
|
1531
|
+
end
|
|
1532
|
+
end
|
|
1533
|
+
|
|
1515
1534
|
# Custom parameter validation for Rails integration
|
|
1516
1535
|
params do
|
|
1517
1536
|
validates :password, presence: true, length: { minimum: 6 }
|
|
1518
1537
|
validates :password, confirmation: true
|
|
1538
|
+
# You can customize nested schema from example above like this
|
|
1539
|
+
profile_attributes_schema do
|
|
1540
|
+
validates :name, presence: { if: :owner_check_profile_name? }
|
|
1541
|
+
end
|
|
1542
|
+
devices_attributes_schema do
|
|
1543
|
+
validates :name, presence: { if: :owner_check_devices_name? }
|
|
1544
|
+
end
|
|
1519
1545
|
end
|
|
1520
1546
|
end
|
|
1521
1547
|
```
|
|
@@ -1613,6 +1639,8 @@ params[:user][:addresses_attributes] = {
|
|
|
1613
1639
|
|
|
1614
1640
|
#### **Controller Integration**
|
|
1615
1641
|
|
|
1642
|
+
There is a separate gem for Rails integration [steel_wheel|https://github.com/andriy-baran/steel_wheel]
|
|
1643
|
+
|
|
1616
1644
|
```ruby
|
|
1617
1645
|
class UsersController < ApplicationController
|
|
1618
1646
|
def new
|
data/lib/action_form/base.rb
CHANGED
|
@@ -67,6 +67,13 @@ module ActionForm
|
|
|
67
67
|
view_context.render html: call.html_safe
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
def internal_call(parent: nil, state: nil, &block)
|
|
71
|
+
@_view_context ||= state&.user_context&.dig(:rails_view_context)
|
|
72
|
+
@_view_context ||= parent.helpers if parent.respond_to?(:helpers)
|
|
73
|
+
@_view_context ||= parent.view_context if parent.respond_to?(:view_context)
|
|
74
|
+
super
|
|
75
|
+
end
|
|
76
|
+
|
|
70
77
|
def helpers
|
|
71
78
|
@_view_context
|
|
72
79
|
end
|
data/lib/action_form/version.rb
CHANGED