New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace for form field ids #1327

Closed
silentvick opened this Issue Jun 30, 2013 · 5 comments

Comments

Projects
None yet
4 participants
@silentvick
Contributor

silentvick commented Jun 30, 2013

I guess there is no :namespace option for form_for helper like in Rails. So,
how do I use several forms for the same model in the same page? Besides of manual settings :id attribute.

@sshaw

This comment has been minimized.

Show comment
Hide comment
@sshaw

sshaw Jun 30, 2013

Contributor

Padrino has no such option. Instead of manually setting :id each time you can do something like this:

  class MyBuilder < Padrino::Helpers::FormBuilder::StandardFormBuilder
    def field_id(field=nil, value=nil)
      result = []
      result << (@options[:namespace] || object_model_name) if root_form?
      result << field_id_fragment if nested_form?
      result << "_#{field}" unless field.blank?
      result << "_#{value}" unless value.blank?
      result.flatten.join
    end
  end

 class App < Padrino::Application
    set :default_builder, MyBuilder

    helpers do
      def form_tag(url, options={}, &block)
        options.delete(:namespace)
        super
      end
    end

    # ...
end  

Which is probably a few test cases and a small refactor away from a patch...

Contributor

sshaw commented Jun 30, 2013

Padrino has no such option. Instead of manually setting :id each time you can do something like this:

  class MyBuilder < Padrino::Helpers::FormBuilder::StandardFormBuilder
    def field_id(field=nil, value=nil)
      result = []
      result << (@options[:namespace] || object_model_name) if root_form?
      result << field_id_fragment if nested_form?
      result << "_#{field}" unless field.blank?
      result << "_#{value}" unless value.blank?
      result.flatten.join
    end
  end

 class App < Padrino::Application
    set :default_builder, MyBuilder

    helpers do
      def form_tag(url, options={}, &block)
        options.delete(:namespace)
        super
      end
    end

    # ...
end  

Which is probably a few test cases and a small refactor away from a patch...

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Jul 1, 2013

Member

@sshaw send a pull request + test and we will pleased to merge it

Member

DAddYE commented Jul 1, 2013

@sshaw send a pull request + test and we will pleased to merge it

@ghost ghost assigned nesquena Jul 1, 2013

@sshaw

This comment has been minimized.

Show comment
Hide comment
@sshaw

sshaw Jul 1, 2013

Contributor

Sure. I'll send something in a day or two.

Contributor

sshaw commented Jul 1, 2013

Sure. I'll send something in a day or two.

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Jul 2, 2013

Member

@sshaw thanks really appreciated!

Member

DAddYE commented Jul 2, 2013

@sshaw thanks really appreciated!

@silentvick

This comment has been minimized.

Show comment
Hide comment
@silentvick

silentvick Jul 6, 2013

Contributor

Thanks, @sshaw!

Contributor

silentvick commented Jul 6, 2013

Thanks, @sshaw!

@ujifgc ujifgc closed this in cbd7a35 Jul 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment