How to convert this Component to SimpleForms 3.1.0.rc1?

18 views
Skip to first unread message

John McDowall

unread,
Sep 13, 2014, 3:47:58 AM9/13/14
to plataformate...@googlegroups.com
Hi Folks, 

I'm trying to upgrade a SimpleForm 2 custom component that looked like this:

module Dresssed
  module SimpleForm
    # Custom SimpleForm component to add a 'Required' tag next to required inputs when
    # there are no errors.
    class RequiredComponent < ComponentBase
      def required_field?
        @input.send(:required_field?)
      end

      def render
        required_tag if required_field? && !@input.has_errors?
      end

      def required_tag
        template.content_tag :div,
                             template.icon_tag("asterisk") + " " + translate_required_text,
                             :class => "help-inline"
      end

      def translate_required_text
        I18n.t(:"simple_form.required.text", :default => 'required')
      end
    end
  end
end

And used to be able to be set like this in the initializer:

    ba.use Dresssed::SimpleForm::RequiredComponent

As far as a I can see, ComponentBase is completely gone in 3.1.0.rc1? 

Any suggestions as to how I should re-implement this component?

Thanks!

Rafael Mendonça França

unread,
Sep 15, 2014, 3:26:06 PM9/15/14
to PlataformaTec - SimpleForm

A component just need to respond to the same method you are defining in the wrapper API. For example the hint component define a method called hint. For you case you would need to define a required method that does what you want it to do. There is no need for base classes anymore.

BTW, I don’t believe we ever had a ComponentBase class.

Rafael Mendonça França
http://twitter.com/rafaelfranca
https://github.com/rafaelfranca

--
You received this message because you are subscribed to the Google Groups "SimpleForm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-simp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John McDowall

unread,
Sep 15, 2014, 3:33:33 PM9/15/14
to plataformate...@googlegroups.com
Wow, that is a lot simpler - thanks for the heads up. 

Yes sorry, turns out that ComponentBase existed in a legacy project I’ve just taken over. 

Thanks!
On Sep 15, 2014, at 12:25 PM, Rafael Mendonça França <rafael...@gmail.com> wrote:

A component just need to respond to the same method you are defining in the wrapper API. For example thehint componentdefine a method calledhint. For you case you would need to define arequiredmethod that does what you want it to do. There is no need for base classes anymore.
--
You received this message because you are subscribed to a topic in the Google Groups "SimpleForm" group.
To unsubscribe from this topic, visithttps://groups.google.com/d/topic/plataformatec-simpleform/1tcNi2bL4Xc/unsubscribe.
To unsubscribe from this group and all its topics, send an email toplataformatec-simp...@googlegroups.com.
For more options, visithttps://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages