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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a30578d111d84b9c748248c82a65eac75389b0696f27dbb3a36a3c437b5643e3
4
- data.tar.gz: 2da98bb16f9368a0f07a70d1c47f904b80421f584c024ae69ea18db009f23bf3
3
+ metadata.gz: d9e95531741195220dd865f28be51b1787718ca2e30638d6bf56aa0407738318
4
+ data.tar.gz: 13711adfe6a993e256644a455cd30f43c711fcf4205d2c8ecbf21d614b927959
5
5
  SHA512:
6
- metadata.gz: 8c9a05b8349c2072c787d95102fd047e6a067e4d367b79c4284c326c75abc2cd05c1a09b38c41dac2d52536cdbb737c927b4f9231a38472cfda66690ed82085f
7
- data.tar.gz: e654910d6f00232ee6995955f48c2089edc70de5151c07ccb247b48758b1ed5c2ad6f3306807b37ac3008d9e0bc722c6ebb7ca1b208ea49aa105d448143133d5
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 Host Object**
695
+ #### **Custom Owner Object**
696
696
 
697
- You can pass a custom host object when initializing a form, allowing you to separate form logic from business logic:
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionForm
4
- VERSION = "0.6.6"
4
+ VERSION = "0.6.7"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrii Baran