VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: newsomjk on August 21, 2013, 16:56:25 PM

Title: Adding classes to registration inputs
Post by: newsomjk on August 21, 2013, 16:56:25 PM
Trying to find where to add a class to registration inputs to make them match the rest of the inputs in our site. No luck so far.

Title: Re: Adding classes to registration inputs
Post by: Maxim Pishnyak on August 21, 2013, 17:06:59 PM
Link?

Also try out Firebug tool (check FAQs in this forum section).
Title: Re: Adding classes to registration inputs
Post by: newsomjk on August 21, 2013, 17:24:57 PM
Sites not live, so I can't give a link.

I know how to inspect it but the issue is that the only class the fields have is "required" unless I click it and then click something else, then it gains the class "invalid."

I know where the invalid class gets set, and I know where the css is for that.

However, I can't find where these fields originally get the class "required" which is what I need to find so I can change it to "required my-input-class" and searching the whole project for "required" returns about 1500 results.
Title: Re: Adding classes to registration inputs
Post by: Maxim Pishnyak on August 21, 2013, 20:07:27 PM
Quote from: newsomjk on August 21, 2013, 17:24:57 PM
Sites not live, so I can't give a link.
What happened with free shared hosting service?
Title: Re: Adding classes to registration inputs
Post by: newsomjk on August 21, 2013, 22:13:52 PM
Viewing the site shouldn't help with this issue anyways. I just can't figure out where the fields are getting the class 'required'.

For instance, this section in administrator/components/com_virtuemart/models/userfields.php:


case 'emailaddress':
if( JFactory::getApplication()->isSite()) {
if(empty($_return['fields'][$_fld->name]['value'])) {
$_return['fields'][$_fld->name]['value'] = JFactory::getUser()->email;
}
} // vmdebug('emailaddress',$_fld);
case 'text':
case 'webaddress':


Neither email address nor text have the attribute "formcode" set in there so I don't understand how they're getting their class.

But here:

case 'password2':
$_return['fields'][$_fld->name]['formcode'] = '<input type="password" id="' . $_prefix.$_fld->name . '_field" name="' . $_prefix.$_fld->name . '" size="30" class="input" />'."\n";
break;


You can see the form code for a password field. Password fields are the only ones I've been able to give the class="input" to.
Title: Re: Adding classes to registration inputs
Post by: Maxim Pishnyak on August 22, 2013, 17:43:47 PM
Quote from: newsomjk on August 21, 2013, 22:13:52 PM
Viewing the site shouldn't help with this issue anyways. I just can't figure out where the fields are getting the class 'required'.
I could do much if you pretend to have better expertise then me.
Title: Re: Adding classes to registration inputs
Post by: newsomjk on August 22, 2013, 18:09:05 PM
I'm not saying I have better expertise but as far as I know, firebug and chrome developer do not show where code gets generated from, especially if it's from a php file. All it can do is show me the styles associated with a class and changes to the DOM. If an element already has a class as soon as the page is loaded, and that class has no styles associated with it, neither Firebug nor chrome developer can point to which file that line of code came from.

If you could just say what file builds those formcodes I could find the file and edit it, it has nothing to do with viewing the site which gets pieced together by php files.
Title: Re: Adding classes to registration inputs
Post by: Maxim Pishnyak on August 22, 2013, 20:39:37 PM
Quote from: newsomjk on August 22, 2013, 18:09:05 PM
I'm not saying I have better expertise but as far as I know, firebug and chrome developer do not show where code gets generated from, especially if it's from a php file.
But they are show css classes (suffixes). Could you solve your issue with using this stuff?
Title: Re: Adding classes to registration inputs
Post by: newsomjk on August 22, 2013, 22:05:44 PM
No, I know how to see what CSS classes are attached to the fields. I can inspect it and see that the input field has the class "required" however that doesn't help in this case because it can't tell me what php file generated the code and gave it the class.

I figured it out, for anyone who needs to add classes to the registration fields:

Look in ../administrator/components/com_virtuemart/models/userfields.php around line 917 for this chunk of code:
case 'text':
case 'webaddress':

$_return['fields'][$_fld->name]['formcode'] = '<input type="text" id="'
. $_prefix.$_fld->name . '_field" name="' . $_prefix.$_fld->name.'" size="' . $_fld->size
. '" value="' . $_return['fields'][$_fld->name]['value'] .'" '
. ($_fld->required ? ' class="required"' : '')
. ($_fld->maxlength ? ' maxlength="' . $_fld->maxlength . '"' : '')
. $readonly . ' /> ';
break;


and replace it with this:

case 'text':
$_return['fields'][$_fld->name]['formcode'] = '<input type="text" id="'
. $_prefix.$_fld->name . '_field" name="' . $_prefix.$_fld->name.'" size="' . $_fld->size
.'" value="' . $_return['fields'][$_fld->name]['value'] .'" '
. ($_fld->required ? ' class=" PUT WHATEVER CLASSES YOU NEED HERE required"' : ' class="PUT WHATEVER CLASSES YOU NEED HERE"')
. ($_fld->maxlength ? ' maxlength="' . $_fld->maxlength . '"' : '')
. $readonly . ' /> ';
break;
case 'webaddress':

$_return['fields'][$_fld->name]['formcode'] = '<input type="text" id="'
. $_prefix.$_fld->name . '_field" name="' . $_prefix.$_fld->name.'" size="' . $_fld->size
. '" value="' . $_return['fields'][$_fld->name]['value'] .'" '
. ($_fld->required ? ' class="required"' : '')
. ($_fld->maxlength ? ' maxlength="' . $_fld->maxlength . '"' : '')
. $readonly . ' /> ';
break;
Title: Re: Adding classes to registration inputs
Post by: Maxim Pishnyak on August 23, 2013, 11:35:29 AM
You probably don't need to hack a core. You solution wouldn't resist next update. Almost everything is possible with the help of css.