Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I just noticed that the make names aren't being sorted in ascending order in the make select field of the make/model selector block. The code in the _vehicle_ymm_build_make_menu function looks correct:
$return = $query->extend('TableSort')
->orderBy('make_name', 'ASC')
->execute();
but the options produced on my form aren't sorted in ascending order (see attached image). What might be wrong? The list of models is sorted correctly.
Comment | File | Size | Author |
---|---|---|---|
#29 | year-values.jpg | 24.2 KB | sah62 |
#24 | drupal-menu.png | 5.8 KB | tonkatuph |
#22 | vehicle-sorting_codingstandards.patch | 6.71 KB | Ignigena |
#20 | vehicle-fix-for-sort-by-make-3-20.patch | 6.62 KB | jppuffnstuff |
#15 | product-fields.jpg | 75.45 KB | sah62 |
Comments
Comment #1
Ignigena CreditAttribution: Ignigena commentedCan you do me a favor and paste the source code of the select menu that is generated for the Make dropdown?
Also, navigate to /ymm/0/1970/make on your site and paste the JSON output here.
Both will help me figure out what may be causing the sorting issue on your end.
Thanks!
Comment #2
sah62 CreditAttribution: sah62 commentedCan do. One thing I just noted: I'm seeing the problem in Chrome 26.0.1410.64 m and IE 9.0.8112.16421. It works with Firefox 20.0.1, all on Windows 7.
Navigating to "http://mysite.com/ymm/0/1970/make" produces a 404. Here's the HTML source:
Comment #3
Ignigena CreditAttribution: Ignigena commentedSeems like a jQuery issue. I am able to replicate this on my end. While the Make menu will sort alphabetically on first load, once you select a year and the list is refreshed it seems to go in order of the Make ID (which is also the option value)
Reclassifying as a bug report and looking into a resolution.
Comment #4
Ignigena CreditAttribution: Ignigena commentedThe issue seems to be that the jQuery each() function returns it's data asynchronously which results in unpredictable sorting of the drop down menu. I've added a very simple sorting function to each menu to ensure that the menus get sorted alphabetically after they are populated.
I've attached a patch below, apply it and see if it solves the problem on your installation. I was able to update my installation and noticed it seemed to fix the problem.
Comment #5
Ignigena CreditAttribution: Ignigena commentedComment #6
sah62 CreditAttribution: sah62 commentedThe patch looks good. It identified an interesting issue, though: case sensitivity. See the attached image. Is it possible to do case-insensitive sort? It might be possible by normalizing the values to either all upper or all lower case prior to making the comparisons.
Comment #7
Ignigena CreditAttribution: Ignigena commentedAhh yes. Try the attached patch as it adds a conversion to lowercase before it compares the values to be sorted.
Comment #8
sah62 CreditAttribution: sah62 commentedLooks great!
Comment #9
Ignigena CreditAttribution: Ignigena commentedCommitted!
Comment #10
sah62 CreditAttribution: sah62 commentedSorry, I need to reopen this. While the select fields in the block form work fine, I just found an issue when trying to tag a node with a year, make, and model value. After selecting a year I try to select a make. I see multiple values for several of the makes as shown in the attached picture. Here's the HTML source:
The issue disappears if I revert to the unpatched versions of the javascript files.
Comment #11
Ignigena CreditAttribution: Ignigena commentedI am unable to duplicate this on my installation or on a fresh Drupal installation. I'm sure you've already tried clearing your caches. What theme are you using for your admin pages? Anything else I can get to try and replicate on my end would be very helpful!
Comment #12
sah62 CreditAttribution: sah62 commentedI'm using the Sky theme. I did clear all caches after patching the files, but I'll do it again and try to do some more debugging later tonight.
Comment #13
sah62 CreditAttribution: sah62 commentedMore info, but no breakthroughs: I just removed and re-installed the module and cleared all caches. The select block works fine. I'm seeing this problem when I try to add values to a field associated with one of my Ubercart products. Every time I select a new model year it adds the make values associated with that year to the available make select options without clearing out the old values first. I'm getting duplicates because this process is cumulative.
Comment #14
Ignigena CreditAttribution: Ignigena commentedGood information to help me replicate. Is this a multi-value field? Or, do you have more than one field on the form?
Comment #15
sah62 CreditAttribution: sah62 commentedThis is a "Vehicle reference" field using the "Year/Make/Model dropdown" widget (see attached image). There are other Ubercart-specific fields on the form. I've seen the problem when the node has only one of these vehicle reference fields and when it has multiple vehicle reference fields.
Comment #16
Ignigena CreditAttribution: Ignigena commentedGot it. Let me try and debug this more this evening. I am using Drupal Commerce rather than Ubercart so my environment is different. I'm going to try and match your environment as close as possible and see if I can get it to replicate.
Thanks for all the info!
Comment #17
sah62 CreditAttribution: sah62 commentedAnother potential consideration: I have both the year/make/model selector block and the product field visible on the same page when editing the product. If I configure the block so that it's displayed only on the front page the problem appears to go away.
Comment #18
sah62 CreditAttribution: sah62 commentedHave you been able to reproduce this behavior? It might be doable as described in #17.
Comment #19
Ignigena CreditAttribution: Ignigena commentedI have been able to reproduce this behaviour. Sorry for the delay in getting a patch out. I'll try to get some work done on this and get it committed. It's been a bit crazy around these parts lately!
Comment #20
jppuffnstuff CreditAttribution: jppuffnstuff commentedTry this patch.
I noticed that the jQuery sort function you were using was appending the sorted Make results to the HTML select element after each AJAX request, rather than sorting and replacing it. So I just sorted the string before it was turned into HTML.
Comment #21
sah62 CreditAttribution: sah62 commentedThanks, the patch seems to do the trick. Everything looks fine.
Comment #22
Ignigena CreditAttribution: Ignigena commentedRerolled the patch due to a few minor coding standards issues specifically indentation and trailing white space. Please review https://drupal.org/coding-standards#indenting
The attached patch should apply cleanly and maintain Drupal coding standards.
Comment #23
sah62 CreditAttribution: sah62 commentedSeems to work fine for me.
Comment #24
tonkatuph CreditAttribution: tonkatuph commentedHi,
First, thank you for the great module.
Second, my years in the make/model selector are not arranged in order descending.
I've tried applying the patches with no luck.
Any idea? I'm using the latest dev version on Drupal 7
Comment #25
Ignigena CreditAttribution: Ignigena commentedCommitted to Dev.
Comment #26
tonkatuph CreditAttribution: tonkatuph commentedI just downloaded the recent dev and it's still not showing in order. Under the issues it says the problem was fixed...any ideas?
Regards
Comment #27
Ignigena CreditAttribution: Ignigena commentedtonkatuph: are you seeing the sorting order incorrect in only the Years drop down or in multiple drop downs? Can you reproduce in all browsers or does it appear to be specific to Firefox (only asking because I see the issue you filed about Firefox and I haven't had a chance to dig into it)
Let me know!
Comment #28
tonkatuph CreditAttribution: tonkatuph commentedI'm seeing the sort order incorrectly in the "Years" dropdown only in the YMM selector for chrome, firefox, ie8 and safari. For some reason it's just not in descending order. It's out of order :D
The issue with firefox seems to be when you select a year in YMM, the make jumps to the last option and doesn't set the focus to remain on make. You have re-select make, then select the actual make name before you select a model to work properly.
And The illegal choice error still seems to pop up in the latest dev when using the MMY selector, but it's and easy fix.
Thanks!
Comment #29
sah62 CreditAttribution: sah62 commentedHere's what I see in Chrome, Firefox and IE 9 with the latest dev release. Only the last few year values on the list (the earliest years) are out of order.
Comment #30
tonkatuph CreditAttribution: tonkatuph commentedThat's funny, I have the same thing. I cleared my database and re-added a bunch of info and it seems to work but the last couple of values are off too.
Regards
Comment #31
Ignigena CreditAttribution: Ignigena commentedVery strange. I'll look into the sorting thing.
tonkatuph: sounds like Javascript is potentially throwing an error that is causing those other JS elements to break. Take a look at your Console window and see if these errors relate to the Vehicle module. If so, please start a new issue since this is new.
Thanks!
Comment #32
Ignigena CreditAttribution: Ignigena commentedComment #33
tonkatuph CreditAttribution: tonkatuph commentedOkay, that was a good idea. Found out that the chosen module was screwing things up with the YMM selector and other drop downs.
Comment #34
tonkatuph CreditAttribution: tonkatuph commentedSeems like it's reordering the years based on the models. Changing the reorder to ASC seems to make the order work, but of course we need DESC.
Comment #35
tonkatuph CreditAttribution: tonkatuph commentedThere seems to be a conflict with the chosen module. Any idea how to fix this?
I can't select the model in the YMM selector. I'm able to select year and make but not model.
Thanks.
Comment #36
Kwaailappies CreditAttribution: Kwaailappies commentedHi
We are building a car parts and modification site, how do I get the search block to check for drupal commerce products, it is not a content type so our products doesn't appear in the search,
Also is it possivble to have the manufacturers "brands" link from images, we have all the images we want to load but want to link the images to the brand name.
Thanks in advance! hope we can use this module!
T
Comment #37
Ignigena CreditAttribution: Ignigena commentedHi kwaailappies, I'd love to help with your questions but can you please post this in a separate issue under the "Support Request" category? This will help ensure this thread stays on topic.
Thanks!
Comment #38
tonkatuph CreditAttribution: tonkatuph commentedAny progress on getting the order corrected?
Comment #39
asaifan CreditAttribution: asaifan commentedLong time and it didn't fix till now !!! i hope someone fixxed this issue