trailblazer / reform

Form objects decoupled from models.
https://trailblazer.to/2.1/docs/reform.html
MIT License
2.49k stars 184 forks source link

Error with dry-validation 1.3 #504

Closed marvintrejoxi closed 4 years ago

marvintrejoxi commented 4 years ago

I have been getting this error with dry-validation in my contract

undefined method `required' for #<Class:0x00007fa7846c9ca0>\nDid you mean?  require

this is my contract:

class BusinessLine::Contract::Create < Reform::Form
      property :name
      property :code
      property :status

      validation name: :default do
        required(:name).filled
      end

      collection :business_line_sections, populator: :business_line_sections! do
        property :section_id
      end

      collection :services, populator: :services! do
        property :name
        property :code
        property :price
        property :status

        collection :additional_services, populator: :additional_services! do
          property :name
          property :code
          property :price
          property :status
        end

        def additional_services!(fragment:, **)
          additional_services.append(::AdditionalService.new)
        end
      end

      def business_line_sections!(fragment:, **)
        business_line_sections.append(::BusinessLineSection.new)
      end

      def services!(fragment:, **)
        services.append(::Service.new)
      end
    end

and Im using those gems:

gem 'trailblazer', '2.1.0'
gem 'trailblazer-rails', '2.1.7'
gem 'trailblazer-operation', '0.6.0'
gem 'reform', '2.3.0.rc2'
gem 'reform-rails', '0.2.0.rc3'
gem 'dry-validation', '1.3.1'
gem 'dry-monads', '1.3.1'

any idea why dry validation doesn't work correctly with reform gem in that version?

seuros commented 4 years ago

@marvintrejoxi , the validation syntax you have is wrong, check out the documentation of Dry.

Also you need to add feature Dry in the contract.

marvintrejoxi commented 4 years ago

@seuros i have that in one initializer

/conf/initializer/reform.rb
require 'reform/form/dry'

Rails.application.config.reform.validations = :dry

Reform::Form.class_eval do
  feature Reform::Form::Dry
end

however, I always get the same error

seuros commented 4 years ago

https://dry-rb.org/gems/dry-validation/1.3/

The block validation is the Dry::Validation::Contract

marvintrejoxi commented 4 years ago

@seuros can you give an example of a contract with validations? because, i dont understand you :(

seuros commented 4 years ago

validation do params do required(:name).filled end end

But check the documentation, a lot of things changed between 0.x and 1.3.

On Thu, Nov 28, 2019 at 7:24 PM Marvin Trejo notifications@github.com wrote:

@seuros https://github.com/seuros can you give an example of a contract with validations? because, i dont understand you :(

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/trailblazer/reform/issues/504?email_source=notifications&email_token=AASIUTZIWEBE4WNL3WZTFG3QWAEFNA5CNFSM4JSXINXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFNH6MY#issuecomment-559578931, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASIUT6R4ZIUTXYUWBFVZFTQWAEFNANCNFSM4JSXINXA .