Two bugs in generating the correct label for "select" and "radio" fields

Started by man.of.earth, September 04, 2019, 16:17:35 PM

Previous topic - Next topic

man.of.earth

Hello,

I found a little bug in
administrator/components/com_virtuemart/models/userfields.php

.'_field' must be appended after $_fld->name in both cases, in order to generate the correct label (otherwise the ID reference for the "for" atribute is wrong)

case 'select':
(...)
line 1143:
$_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.genericlist', $_values, $_prefix.$_fld->name.'_field', $_attribs, 'fieldvalue', 'fieldtitle', $_selected);

(...)

case 'radio':
line 1156:
$_return['fields'][$_fld->name]['formcode'] =  JHtml::_('select.radiolist', $_values, $_prefix.$_fld->name.'_field', $_attribs, 'fieldvalue', 'fieldtitle', $_selected);



StefanSTS

Thanks for reporting:

EDIT. xxx Some wrong example xxx

Do you have an example/BE link for the missing _field?
--
Stefan Schumacher
www.jooglies.com - VirtueMart Invoice Layouts

Please use only stable versions with even numbers for your live shop! Use Alpha versions only if you know what risk you are taking.

man.of.earth

I undid the changes and I'll keep them so by tomorrow, so you can check the error out. See here: https://validator.w3.org/nu/?showsource=yes&doc=https%3A%2F%2Fwww.proxima-mundi.ro%2Fmagazin%2Fcontul-meu#l1517c45 - error #8 (it's "my account" page, title field; no radio button on that form)

<label class="title" for="title_field"></label>↩
</td>↩
<td>↩
<select id="title" name="title" class=" vm-chzn-select">

StefanSTS

Thanks for the link, just wanted to know where it shows.
In frontend, user registration.

Good find.

You will find also that there are non allowed attributes like step, init and value that should be something like data-vm-init ... or similar in the quantity inputs.

--
Stefan Schumacher
www.jooglies.com - VirtueMart Invoice Layouts

Please use only stable versions with even numbers for your live shop! Use Alpha versions only if you know what risk you are taking.

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

man.of.earth

Quote from: StefanSTS on September 05, 2019, 01:47:07 AM
You will find also that there are non allowed attributes like step, init and value that should be something like data-vm-init ... or similar in the quantity inputs.

As for the thing you brought up, I put type = "number" instead of type="text" for the quantity box, so
<input type="number" class="quantity-input js-recalculate" name="quantity[]" data-errstr="You can buy this product only in multiples of %s pieces!" value="1" init="1" step="1">

instead of
<input type="text" class="quantity-input js-recalculate" name="quantity[]" data-errstr="You can buy this product only in multiples of %s pieces!" value="1" init="1" step="1"/>

This is very useful in the cart page, as the quantities can be changed more easily ("number" type has up and down arrows, on hover) in combination with the update button.
<td class="vm-cart-item-quantity"...
<input type="number".../>


And it validates more :)

Milbo

Quote from: arcturus on September 04, 2019, 16:17:35 PM
Hello,

I found a little bug in
administrator/components/com_virtuemart/models/userfields.php

.'_field' must be appended after $_fld->name in both cases, in order to generate the correct label (otherwise the ID reference for the "for" atribute is wrong)

case 'select':
(...)
line 1143:
$_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.genericlist', $_values, $_prefix.$_fld->name.'_field', $_attribs, 'fieldvalue', 'fieldtitle', $_selected);

(...)

case 'radio':
line 1156:
$_return['fields'][$_fld->name]['formcode'] =  JHtml::_('select.radiolist', $_values, $_prefix.$_fld->name.'_field', $_attribs, 'fieldvalue', 'fieldtitle', $_selected);




We had to remove the fix. Currently it just changes the used input name, which also changes the send data by the form.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

stAn99

the current implementation in vm3.6.1-DEV is wrong per what i understand.

the current code changes NAME of the form field and thus alters the index in POST and further modificastions would be needed in both core VM and all 3rd parties that use the data from post.

current code for select is:

$_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.genericlist', $_values, $_prefix.$_fld->name.'_field', $_attribs, 'fieldvalue', 'fieldtitle', $_selected);


the correct code for select:

$_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.genericlist', $_values, $_prefix.$_fld->name, $_attribs, 'fieldvalue', 'fieldtitle', $_selected,$_prefix.$_fld->name.'_field');


same for radios - updated code:

$_return['fields'][$_fld->name]['formcode'] =  JHtml::_('select.radiolist', $_values, $_prefix.$_fld->name, $_attribs, 'fieldvalue', 'fieldtitle', $_selected, $_fld->name.'_field');


notes:
- labels are using IDs by default and names only in html5 as fallback
- VM had ever since always added "_field" to names to create ID with excpetion of virtuemart_country_id and virtuemart_state_id which had been updated in previous VM3

my code proposal creates IDs with "_field" and does not alter names as it always was...

i don't really understand why VM would want to use joomla's select.radiolist instead of using it's own sublayouts where shop admins can easily inject new classes to support their custom styling libraries. disadvanta now is that joomla seems to add VALUE to the ID if array field is provided (such as checkbox) which can lead to unpredicted code upon different joomla versions.

best regards, stan


----
RuposTel.com
www.rupostel.com
Your customized checkout solution for Virtuemart

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/