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

Select type is being sorted by the collection key #430

Closed
andrerpbts opened this issue Dec 18, 2014 · 7 comments
Closed

Select type is being sorted by the collection key #430

andrerpbts opened this issue Dec 18, 2014 · 7 comments

Comments

@andrerpbts
Copy link

Hi,

I'm using the best_in_place, to edit values with select type. But, I discovered that it isn't ordering like the collection I've set.

So, after some tests, I figured out if you pass the hash in this way:

<%= best_in_place @user, 
                  :country, 
                  :type => :select, 
                  :collection => {"4" => "France", "3" => "Germany", "2" => "Italy", "1" => "Spain" } %>

You'll get the result:

<option value="1">Spain</option>
<option value="2">Italy</option>
<option value="3">Germany</option>
<option value="4">France</option>

It's all happens because the JSON's parse. It's ordering by the key number, if a hash is given, see:

JSON.parse('{"4":"France", "3":"Germany", "2":"Italy", "1":"Spain"}'); 
-> Object { 1: "Spain", 2: "Italy", 3: "Germany", 4: "France" }

So, I think the right way to build this element, is using Array, like:

JSON.parse('[["4","France"], ["3","Germany"], ["2","Italy"], ["1","Spain"]]'); 

What do you think?

@stereodenis
Copy link

@andrerpbts I'm working on this

@seuros seuros closed this as completed in b0412ab Dec 19, 2014
seuros added a commit that referenced this issue Dec 19, 2014
@bvogel
Copy link

bvogel commented Mar 17, 2015

@seuros Can we please reopen this? I'm still seeing the ordering issue. When building with collection: [[1, 'Spain'], [3, 'Germany'], [2, 'Italy'], [4, 'France']] the generated select will show 'Spain', 'Italy', 'Germany', 'France' - even using the provided code from the Readme. I'm on Rails 4.2 with ruby 2.1.5.

@seuros
Copy link
Collaborator

seuros commented Mar 17, 2015

Try master please.

@bvogel
Copy link

bvogel commented Mar 17, 2015

Tried master - no dice. Aren't master and 3.0.3 identical in the relevant sections?

@bvogel
Copy link

bvogel commented Mar 17, 2015

@stereodenis may be 7e83193 caused a regression?

@maland
Copy link

maland commented Mar 19, 2015

i am also using 3.0.3 and experiencing the same problem

@stereodenis
Copy link

@andrerpbts this PR should fix right order #459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants