VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: remeedella on March 17, 2013, 01:29:40 AM

Title: add a class tag to auto-generated customfields
Post by: remeedella on March 17, 2013, 01:29:40 AM
Hey all,

I might need someone with a little programming experience that I don't have to help me out.
I have some custom fields assigned to products and I was wondering about the way they are displayed in the product details page. My issue is I am building something out of bootstrap and everything is going swimmingly so far in converting to fluid. The only thing standing in my way right now is those darned input fields. They do not adjust to page fluidly, but I can make them!

It looks something like this for the custom fields.<span class="product-field-display"><select name="customPrice[1][18]" id="customPrice118">. The <select name="" id=""> is always auto generated and what I need to do is add a class to all of those input fields, I want to add let's say a class="span9" to the actual <select> reference. It won't work to add it with the span class="product-field-display" it needs to be added directly to the drop down input field thats a child of the span tag. I've tested it and I don't really want to look for any other workarounds or methods so my question is, I know which file or the main one where this all works but I don't know how to select just that <select> tag and add a class="span9" to it always when there is one. Can anyone help me with some coding to tie that in? As far as I know this is the file where it is referenced and needs some code added. default_customfields.php


I'll paste it:

<div class="product-fields">
       <?php
       $custom_title = null;
       foreach ($this->product->customfieldsSorted[$this->position] as $field) {
          if ( $field->is_hidden ) //OSP http://forum.virtuemart.net/index.php?topic=99320.0
             continue;
         if ($field->display) {
       ?><div class="product-field product-field-type-<?php echo $field->field_type ?>">
          <?php if ($field->custom_title != $custom_title) { ?>
             <span class="product-fields-title" ><?php echo JText::_($field->custom_title); ?></span>
             <?php
             if ($field->custom_tip)
            echo JHTML::tooltip($field->custom_tip, JText::_($field->custom_title), 'tooltip.png');
         }
         ?>
              <span class="product-field-display"><?php echo $field->display ?></span>
              <span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>
          </div>
          <?php
          $custom_title = $field->custom_title;
         }
       }
       ?>


Cookies will be rewarded
Title: Re: add a class tag to auto-generated customfields
Post by: PRO on March 17, 2013, 03:27:24 AM


thats the wrong file

cart variants custom fields are done in

default_addtocart.php

You can do this a couple ways
Here is 1
str_replace

switch this
<?php echo $field->display; ?>

for this

<?php $field->display = str_replace( '"<select', '"<select class="class" ', $field->display ); ?><?php echo $field->display; ?>


please test, cause I havent
Title: Re: add a class tag to auto-generated customfields
Post by: remeedella on March 17, 2013, 05:19:44 AM
this code did not work :(
Title: Re: add a class tag to auto-generated customfields
Post by: PRO on March 17, 2013, 14:20:06 PM


<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration("
   jQuery(document).ready(function($) {
    $('select').addClass('class-name');
   });
");
?>
Title: Re: add a class tag to auto-generated customfields
Post by: remeedella on March 17, 2013, 15:46:38 PM
where do I place this!? Right before <?php echo $field->display; ?>    ???
Title: Re: add a class tag to auto-generated customfields
Post by: PRO on March 17, 2013, 17:05:37 PM
that code can be placed anywhere

as long as its not inside any <?php tags

You can place it close to the top in

views/productdetails/tmpl/default.php
Title: Re: add a class tag to auto-generated customfields
Post by: remeedella on March 17, 2013, 17:20:32 PM
I added it literally before anything on that page and you're right! This works, you're a god amongst men.

You can now see the fluid in action when you shrink http://www.newreleasewall.com/primetimegourmet/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=2&virtuemart_category_id=3

Thankssss
Title: Re: add a class tag to auto-generated customfields
Post by: PRO on March 18, 2013, 00:43:35 AM
dont see it in the code
Title: Re: add a class tag to auto-generated customfields
Post by: remeedella on March 18, 2013, 20:45:09 PM
What do you mean? It is working, "span9" class is added to the select fields
Title: Re: add a class tag to auto-generated customfields
Post by: PRO on March 18, 2013, 22:45:35 PM
picture attached

[attachment cleanup by admin]
Title: Re: add a class tag to auto-generated customfields
Post by: remeedella on March 18, 2013, 23:22:34 PM
My bad dude! I just realized, I think I overwrote it because I forgot to do a template override. If you're online now can you re-check? Should be dandy!
Title: Re: add a class tag to auto-generated customfields
Post by: PRO on March 19, 2013, 02:07:09 AM
yes that works


and learn to use firebug if you dont know how yet
http://forum.virtuemart.net/index.php?topic=102850.0

Title: Re: add a class tag to auto-generated customfields
Post by: remeedella on March 19, 2013, 04:46:55 AM
of course I know firebug, why would I not know firebug