1

I'm trying to pass association values as hidden field in simple form

so same functionality like when you do ...

= simple form for @document do |f|
 = f.association :clients

...but will generate hidden field insted

I'm trying to do it as this

  = f.association :clients, as: hidden 

but that wont work obviously

only thing that works for me is

%input{ name: 'document[client_ids][]', value: '1'}
%input{ name: 'document[client_ids][]', value: '2'}
%input{ name: 'document[client_ids][]', value: '3'}
1
  • have you tried = f.association :clients, type: 'hidden' ?
    – MrYoshiji
    Commented Nov 9, 2012 at 15:51

3 Answers 3

2

Maybe

=f.hidden_field :client_id, :value => "some value"

but I think you'd be better of explaining the bigger picture and then we can suggest a suitable rails answer for you. In most cases using hidden fields is a sign that something should be done a better way.

1

An array is sent on submit from associations in simple form. The following will allow for this using a hidden field:

  <%= f.hidden_field('client_ids][', value: "some value") %>

(Note: The reversed brackets are important)

0

I think

<%= f.association :clients, input_html: { hidden: true } %>

should work.

2
  • no this wont work for 2 reasons, Simple form f.association is excepting first parameter association field symbol, (e.g. :clients for has_many :clients) and even if I generate these fields, they are still select html tag with just hidden=hidden argument Commented Nov 15, 2012 at 17:30
  • what's wrong with hidden="hidden"? whatwg.org/specs/web-apps/current-work/multipage/… Commented Nov 15, 2012 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.