Google Groups

Re: collection , :include_blank false not taken in account


erwin Apr 11, 2012 5:04 AM
Posted in group: SimpleForm
I have seen the 'gotcha' in Rails doc.. so it seems impossible to get
rid of the first null value on the client..
need to eject it from the list upon reception on the server ...

On Apr 11, 1:47 pm, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:
> Ah great Vasiliy, I didn't remember that happens to select + multiple as well, thanks :D
>
> The hidden field might be before the select he posted, so the full html would help to check that.
>
> --
> At.
> Carlos Antonio
>
>
>
>
>
>
>
> On Wednesday, April 11, 2012 at 8:31 AM, Vasiliy Ermolovich wrote:
> > When you are using multiple select rails generates hidden input with blank value for you:http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelp...
> > But I don't see it in your generated html :\
>
> > 2012/4/11 Carlos Antonio da Silva <carlosantoniodasi...@gmail.com (mailto:carlosantoniodasi...@gmail.com)>
> > > The html select you've sent is the only output you get, or you have the entire input with wrapper? I can't see SimpleForm generating anything wrong with that, which makes me think that might be the browser sending an empty value or something.
>
> > > --
> > > At.
> > > Carlos Antonio
>
> > > On Wednesday, April 11, 2012 at 7:29 AM, erwin wrote:
>
> > > > just for info : tested with simple_form_bootstrap example, same
> > > > issue :
>
> > > > new article params
> > > > params
> > > > {"utf8"=>"✓",
> > > > "authenticity_token"=>"E4mnngwuKryEfEzc3O2H78tyiQizhWWY2cMx7dA0fHI=",
> > > > "article"=>{"name"=>"", "published"=>"0", "content_type_1"=>[""],
> > > > "content_type_3"=>["", "Blog", "Announce"], "category"=>"",
> > > > "content"=>""}, "commit"=>"Create Article", "action"=>"create",
> > > > "controller"=>"articles"}
>
> > > > we can see : "content_type_3"=>["", "Blog", "Announce"] 3 items
> > > > but only 2 selected in the list
>
> > > > On Apr 11, 12:13 pm, erwin <kadou...@gmail.com (http://gmail.com)> wrote:
> > > > > I am displaying a collection w multiple select, and I get a wrong list
> > > > > of selected items...
>
> > > > > = f.input :local_contacts, :collection =>
> > > > > member_options(@project), :label_method => :first, :value_method
> > > > > => :last, :selected => @project.local_contacts.map{|local_contact|
> > > > > local_contact.user[:id] }, :input_html => { :multiple =>
> > > > > true }, :include_blank => false, :label => t(:local_contact, :count =>
> > > > > 2).capitalize
>
> > > > > this generates the following html :
>
> > > > > <select name="project[local_contacts][]" multiple="multiple"
> > > > > id="project_local_contacts" class="select optional">
> > > > > <option selected="selected" value="1">Mr Jean Bordeaux</option>
> > > > > <option selected="selected" value="16">Mme User1 Client1</option>
> > > > > </select>
>
> > > > > and I get 3 items as param, first is blank....
> > > > > params[:project]["local_contacts"]  =>   ["", "1", "16"]
>
> > > > > I tried to move the :include_blank => false  option into
> > > > > the :input_html  hash, same issue...
>
> > > > > looking into the source code I've seen a skip_include_blank?  false by
> > > > > default ... which could explain why a get a blank item , but how to
> > > > > get rid of it ?
>
> > > > > thanks for feedback