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.
Clicking on a radio button on product pages (for grouped product attributes) forces a little ajax loader (presumably to change over the single product for the form) and removes any JQ UI classes used for custom styling.
I have attached the original (before a radio is selected) and after.
Reading up on another blog about JQ UI itself, it mentioned something about 'bind' - but it's all a bit of my depth.
Comment | File | Size | Author |
---|---|---|---|
After selecting a different radio. | 43.44 KB | gamepaused | |
Initial page load before selecting a different radio. | 58.07 KB | gamepaused |
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedOooh, that looks very sharp. It would be a very nice solution to #1180016: Attributes (colors e.g.) as images in product display ? as well.
What you're experiencing is the Forms API's AJAX refresh. When the throbber shows, it's because the form is being submitted, rebuilt, and re-rendered server side. We then return part of the form to be replaced in the page. It appears the re-rendered form does not include your classes, and the question is why. To know that I'd need to see how you're attempting to add the classes. If you do it through a form alter, the classes should be re-applied when the form is rebuilt. If you were just doing it via JavaScript after the page loaded, then you'd lose the classes.
Comment #2
latulipeblanche CreditAttribution: latulipeblanche commentedYes @gamepaused, show us how you did it !! :)
I'm looking for, how to get "Images as "select-list" of Add-to-cart-form" (http://www.drupalcommerce.org/node/466#comment-1411).
Comment #3
gamepaused CreditAttribution: gamepaused commentedHey!
Ok, so I used the standard method of adding the button JQ UI stuff as found on http://jqueryui.com/demos/button/
I think it inserts a few classes and labels dynamically, which you can then style up really easy.
Code added to top of the product tpl -
I also had to overide the radio and radios to add a radio ID to the forms.
I'm such a newb but it's almost working!
Comment #4
gamepaused CreditAttribution: gamepaused commentedAgain, I read something somewhere about 'keeping' dynamic classes when using external libraries using something called 'bind' - but I'm a designer and it gets a bit over my head.
Ubercart did things differently, so the classes remain.
Comment #5
gamepaused CreditAttribution: gamepaused commentedDid anybody find a solution to this?
Thinking - it could be useful if we could add classes to sold out items too - so they could be styled differently (with no mouseover for example).
Comment #6
Damien Tournoud CreditAttribution: Damien Tournoud commented@gamepaused: you are probably not loading your Javascript properly. It needs to go into a
Drupal.behavior
thingie.See http://drupal.org/node/756722#behaviors for more.
Comment #7
gamepaused CreditAttribution: gamepaused commentedYeah - behavior was needed so that the jqui will work after any other calls.
Basically - adding this to a js file was all that was needed -
(function ($) {
Drupal.behaviors.mytheme = {
attach: function (context, settings) {
$('#radio', context).buttonset() ;
}
};
}(jQuery));
So in theory - you can style away to your hearts content :)
The little ajax spinner thing though - any ideas on how to style/position that? It happens so fast I can't see any output.
Comment #8
gamepaused CreditAttribution: gamepaused commentedComment #9
gamepaused CreditAttribution: gamepaused commentedWhere is the best place to post how I achieved all this? Personal site with screenshots?
Hopefully somebody can direct it further (and less of an hack) if I post the results.
Comment #10
rszrama CreditAttribution: rszrama commentedIf you do that we could link it in from DC.org and wherever we need. I'll tweet it up, too. : )
Maybe we can just keep a handbook here on d.o linking to various tutorials like Views Slideshow did for the one I posted to my blog.
Comment #11
latulipeblanche CreditAttribution: latulipeblanche commented@rszrama Do you think that this could work with the image-colors representing the colors of the products ?
Comment #12
gamepaused CreditAttribution: gamepaused commentedI'm going to look into this too so will post up with the rest.
Ideally - would be great for somebody to check out my template.php stuff
Comment #13
xicom3 CreditAttribution: xicom3 commentedi dont knw.. not working for me :| any suggestion
Comment #15
MickL CreditAttribution: MickL commentedfirst this didn't worked for me, too. then i figured out that it is important to set the drupal_add_library and the drupal_add_js!
so the full code to put in your productdisplay.tpl.php is:
(setted this up to the class .form-radio instead of #button)
Comment #16
AJen CreditAttribution: AJen commentedNewbie question: So where do the images go? in the tpl?
Comment #17
timodwhit CreditAttribution: timodwhit commented@aussiejen did you figure out where images go?
A bigger newb question though: Where does the code go? I have looked at quite a bit of documentation but nothing quite covers how to handle this.
Thanks for the help.
Comment #18
MickL CreditAttribution: MickL commentedwhat i posted was in my productnode.tpl.php
then it is possible to give the labels background images with css.
but there was a big problem maybe someone could work this out?
every input has a id, e.g.: "edit-attributes-field-color-red". So in css the only way to give the label a background is:
when clicking on a color all colors are rerendered and the id changes to "edit-attributes-field-color-red--2", "edit-attributes-field-color-red--3", "edit-attributes-field-color-red--4", ... and so on.
So after clicking on another color all background images are gone. so i needed to do some javascript for all of my 30 colors:
$('label[for^="edit-attributes-field-farbe-color-red"]').css('background-image','url(files/color/00.jpg)');
the little hook "^" says "all labels that start with edit-attributes-field-farbe-color-red"
I would please you "commerce team" to give the input's a class too which does not change. so its
<input id="edit-attributes-field-color-red" class="edit-attributes-field-color-red">
and the class does not change after reloading the input fields.when this is worked out i will write tutorial how to theme the (color) dropwdown into pictures.
Comment #19
rszrama CreditAttribution: rszrama commentedI'm pretty sure that's a different issue than this one. This is just a core Drupal issue in that it increments IDs on AJAX refreshes. To get around it, I rely on classes (even otherwise unique classes that match element IDs) to target my styles. See for example our targeting of product fields injected into node displays.
Comment #20
palamidaras50 CreditAttribution: palamidaras50 commentedGreat issue, it really helped me.
I would like also to add my final solution (thanks to all your posts):
1) I used a standard select list field for the color.
2) I added all the predefined web color values to that list (X11 color names - Aliceblue, Antique white,.....)
3) The client who inserts a product just selects a color from the list.
4) I used the following code to the node--product-display.tpl.php: (thanks to all your posts)
----------------
5) Style the ui.button in the css
You could use taxonomy instead of standard list of course, but my main point is that you don't have to use an image field. The little box gets the respective color just with the following jquery code :
$(this).css('background',$(this).children(':first').text());
Therefore the client doesn't have to upload separate images for each product (or external jpgs like 'url(files/color/00.jpg)). unless you really need it.
Comment #21
MishaZP CreditAttribution: MishaZP commentedpalamidaras50, I want to add this code to my e-shop. Write me please, what i need to edit in this. thanks in advance
Comment #22
Summit CreditAttribution: Summit commentedHi, still I do not get this to get images as select options...for image-site this is very importent. I know this issue is closed, but may be someone has made a module/sandbox to get this easy done?
greetings, Martijn
Comment #23
Summit CreditAttribution: Summit commentedsorry- double post..