Skip to content
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
Closed

Namespace for form field ids #1327

silentvick opened this issue Jun 30, 2013 · 5 comments
Assignees
Milestone

Comments

@silentvick
Copy link
Contributor

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
Copy link
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
Copy link
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
Copy link
Contributor

sshaw commented Jul 1, 2013

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

@DAddYE
Copy link
Member

DAddYE commented Jul 2, 2013

@sshaw thanks really appreciated!

@silentvick
Copy link
Contributor Author

Thanks, @sshaw!

@ujifgc ujifgc closed this as completed in cbd7a35 Jul 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants