Replace "Select some options" with filter name?

  • Posts: 2143
  • Thank you received: 747
9 years 4 months ago #206526

-- url of the page with the problem -- : local
-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.5.3

Hi,

I have several dropdown filters, all with title position = inside, to save space.
One is single dropdown, and the title (= filter name) indeed shows inside.
Several others are multiple drop downs (typical setup as per attached screenshot), but instead of the titles there's "Select some options" showing for all of them, making them all look the same. Only if you click on one, the title shows in the first row of options.

See here when closed:



See here when opened:


How can the filter title/name be displayed instead of "Select some options"?

(I have Chosen library enabled, and it seems to require a hack of a JS file. I'm not afraid of making the change along with note to myself for updates, but I suffer from lack of JS coding capabilities... so, I guess I'm asking you kindly to tell me what to change exactly. Thanks!)

Edit:
See update in next post.


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )
Attachments:
Last edit: 9 years 4 months ago by lousyfool. Reason: update in next post

Please Log in or Create an account to join the conversation.

  • Posts: 2143
  • Thank you received: 747
9 years 4 months ago #206535

lousyfool wrote: (I have Chosen library enabled, and it seems to require a hack of a JS file.


Update:

So, I tried to quickly learn a bit about chosen and figured that one doesn't need to mess with its JS.
I went to see how you're doing it for single dropdown filters with title position inside, and found that you're making the magic happen in /administrator/components/com_hikashop/classes/filter.php, correct?

Looks like under "class hikashopSingledropdownClass extends hikashopFilterTypeClass" the block
if($filter->filter_options['title_position']=='inside'){
			$html.='<OPTION VALUE="none">'.$filter->filter_name.'</OPTION>';
is inserting filter_name for single dropdowns.

But under "class hikashopMultipledropdownClass extends hikashopSingledropdownClass", there's seemingly nothing to make it work for multiple dropdowns.
I tried messing with code a bit there, but can't get it to work. So, please let me re-phrase my question:

Can you please tell me what code to put where so multiple dropdown filters with title positioned inside have the same functionality as single dropdowns?

Thanks again!


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 4 months ago #206561

Hi,

As you put in your last message, the class hikashopMultipledropdownClass extends from the class hikashopSingledropdownClass
So this means that it does the same processing by default.
You can see that the only thing that changes is the multiple parameter which is added to the dropdown to make it behave as a multiple dropdown but all the rest is the exact same.
So I don't see why it would work for single dropdowns and not for multiple dropdowns.
I don't think that you need to change any code.
I think that it must come from something else because the text "Select some options" is not in HikaShop by default.

Please Log in or Create an account to join the conversation.

  • Posts: 2143
  • Thank you received: 747
9 years 4 months ago #206575

nicolas wrote: I think that it must come from something else because the text "Select some options" is not in HikaShop by default.

Correct, the text is inside the Chosen JS files /media/jui/js/chosen.jquery.js and /media/jui/js/chosen.jquery.min.js
It's a placeholder (placeholder_text_multiple) when no options are selected for a multiple select.
See here, this is one of the references I found: api.devtrac.org/api/devtrac/libraries!ch...options.html/7.x-1.x

nicolas wrote: So I don't see why it would work for single dropdowns and not for multiple dropdowns.
I don't think that you need to change any code.

Sorry, but it does require different code than single dropdown. For single dropdowns the default placeholder is placeholder_text_single = "Select an option" (singular). Obviously, you are replacing that with filter_name, but since it requires different code for multiple drop downs and the placeholder, it doesn't work the same way. So, simply extending the class doesn't work.

With the Chosen library enabled in HikaShop, I created two filters from the same custom field, one single, the other multiple dropdown. Please look at the different HTML and note the difference. I highlighted what is visible with dropdowns closed, and you see that for the single dropdown the placeholder was replaced by "Region (single)", and for the multiple dropdown it's not "Region" as should be, but it's still the default ("Select some options" as per Chosen JS):

Single dropdown:


Multiple dropdown:


Please look further into it and amend the necessary code to the classes/filter.php to make "Title position = inside" usable with multiple dropdowns and Chosen. Can't wait for a snippet... will be happy to be your guinea pig, haha!

Many thanks in advance!


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )
Attachments:
Last edit: 9 years 4 months ago by lousyfool.

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 4 months ago #206631

So it's chosen which adds that extra value with its javascript.

In that case, you want to change the line:
$multiple='multiple="multiple" size="5"';
to:
$multiple='multiple="multiple" size="5" data-placeholder="'.$filter->filter_name.'"';
in the file administrator/components/com_hikashop/classes/filter.php
That will add the filter name as placeholder in the select so that chosen can use it instead of the "select some options" text.
Let us know how it goes. And if it works fine without chosen, or with the other title positions. If yes, that's something we could add by default to HikaShop.

The following user(s) said Thank You: lousyfool

Please Log in or Create an account to join the conversation.

  • Posts: 2143
  • Thank you received: 747
9 years 4 months ago #206659

:woohoo: YESSSSSS!!! Thank you, thank you!

So glad it works, because with Chosen the selects and dropdowns look already better than the usual pack out of the box, consistently across most browsers, and can further be styled. And the titles inside make real good sense, look even better, and save space, too! Thanks a ton for the quick and good fix! If it doesn't do anything bad to the "non-Chosen" elements, please leave the code in so others benefit as well.

Hmm, guess the only other option would have been to disable the "Title inside" button if multiple dropdowns and Chosen are chosen..... haha, just kidding.


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )

Please Log in or Create an account to join the conversation.

Time to create page: 0.091 seconds
Powered by Kunena Forum