Characteristics display as buttons

  • Posts: 67
  • Thank you received: 0
7 years 5 months ago #254569

Hello,

I would like to "simulate" radio buttons to be something like regular buttons (check screenshot). When user click on desired size of cloth it should change color and stay in that color. If user pick other size it ll change color when he click on other button. I managed to change display, but button color changing doesnt work. Button changing color on :hover but not on :checked. What am I doing wrong? :)

I am doing changes on local, so u can't check it on live site

.hikashop_product_characteristics_table input[type=radio] {
	display: none;
	}
.hikashop_product_characteristics_table label{
    display:inline-block;
    margin: 2px;
    padding: 4px 12px;
    border: 1px solid #333;
	cursor: pointer;
}
.hikashop_product_characteristics_table  label  + input[type=radio]:checked { 
    background: blue;
}

Thanks,
Jelena

Attachments:

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

  • Posts: 200
  • Thank you received: 75
7 years 5 months ago #254575

Hi,

the line

.hikashop_product_characteristics_table  label  + input[type=radio]:checked {
has two errors. First of all, the radion button is inside the label element, not a sibling of it, so the + is not correct (you should use the > selector). Secondly and more importantly, the CSS will select the element coming after the + and so your CSS is changing the background colour of the radio button, not the label.
It is a bit unfortunate that the Hikashop code places the input element inside the label, because in CSS it is not possible to style a parent element, so it's not possible to achieve what you want just through CSS.

But there are two possible ways:
1. You could use Javascript to add for example a class to the label when the radio button is checked.
2. You can make a small modification to the Hikashop code for the characteristics to add a span around the label text (the "74" in your image).
In the file /administrator/components/com_hikashop/types/characteristic.php you could change line 212 from
$values[$k]=$value->characteristic_value;
to
$values[$k]='<span>'.$value->characteristic_value.'</span>';

Now you will see a span element around the "74", and you can then easily style it with CSS using the selector
.hikashop_product_characteristics_table input[type=radio]:checked + span {
Note however that this is a modification in a Hikashop core file and it will be undone when you update Hikashop, so it's not ideal. Perhaps we can ask Hikashop to add a span around the label value so it's easier to style it.

Hope this helps. Kind regards,

Last edit: 7 years 5 months ago by GW.
The following user(s) said Thank You: kivici

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

  • Posts: 67
  • Thank you received: 0
7 years 5 months ago #254581

Hello,

Thank u for the answer, but there is a problem. What I am trying to achive have most of online shops around. Its basic option for user to select size of cloth and only when user choose size that button changing color on click (and stying in that color).
I don't have knowledge in js. I guess on click it should add class I want, but I can't figure it out.
About changing core of Hikashop. I did try but what u suggested but it changed color of all labels (not only on click). I need it to change (and stay) only on click (so user know he choosed proper size)

I need something similar to this: jsfiddle.net/j08691/5ovLtdfn/
radio buttons should be hidden and labels should change color on click

Last edit: 7 years 5 months ago by kivici.

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

  • Posts: 200
  • Thank you received: 75
7 years 5 months ago #254590

Hi,

if you use the selector like in my answer

.hikashop_product_characteristics_table input[type="radio"]:checked + span {
it's impossible it will change the colour of all labels, because as you can see from the :checked part it will only target the input which is currently selected, so you must have made a mistake or possibly have some other CSS interfering. We use exactly the above CSS and it works fine, highlighting only the selected size, so maybe you can check carefully to make sure your CSS is correct. Or if you're able to give a link to your page, it would be easy to check.

If you prefer to use Javascript, the fiddle is correct, you might want to target not every single input element on your website, but only the characteristics input elements in the hikashop_product_characteristics_table:
// REGISTER A CLICK ON A SIZE LABEL AND ADD THE CLASS CHECKED TO IT
jQuery('table.hikashop_product_characteristics_table input').click(function(){
     jQuery('table.hikashop_product_characteristics_table label').removeClass('checked');
     jQuery(this).parent().addClass('checked');
});

//ON PAGE LOAD SELECT THE DEFAULT SIZE LABEL
jQuery('table.hikashop_product_characteristics_table input:checked').parent().addClass('checked');

And for this you just need to change your css rule to:
.hikashop_product_characteristics_table label.checked { 
    background: blue;
}

The above code works perfectly as well.
Hope this helps. Kind regards,

The following user(s) said Thank You: Jerome, kivici

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

  • Posts: 67
  • Thank you received: 0
7 years 5 months ago #254656

Thanks a lot for help. I used css as u said and it's working! :)

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

  • Posts: 67
  • Thank you received: 0
4 years 1 month ago #316298

Hello,

I have been using option to customize characteristics on product page in the way explained in this topic.

After every update I would change: /administrator/components/com_hikashop/types/characteristic.php

I would change line 221 to: $values[$k]='<span>'.$value->characteristic_value.'</span>';

However, I am testing latest Hikashop version on my local, and I dont see span around characteristic anymore so css customize doesnt work.

What changed? I cant figure it out.

Last edit: 4 years 1 month ago by kivici.

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

  • Posts: 81539
  • Thank you received: 13069
  • MODERATOR
4 years 1 month ago #316303

Hi,

The code has been moved to the file show_block_characteristic.php so that you can do such modification via the menu Display>Views as a view override and you won't have to redo it after each update :)

The following user(s) said Thank You: kivici

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

Time to create page: 0.085 seconds
Powered by Kunena Forum