VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: man.of.earth on September 04, 2019, 16:17:35 PM

Title: Two bugs in generating the correct label for "select" and "radio" fields
Post by: man.of.earth 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);


Title: Re: Two bugs in generating the correct label for "select" and "radio" fields
Post by: StefanSTS on September 04, 2019, 17:51:00 PM
Thanks for reporting:

EDIT. xxx Some wrong example xxx

Do you have an example/BE link for the missing _field?
Title: Re: Two bugs in generating the correct label for "select" and "radio" fields
Post by: man.of.earth on September 04, 2019, 22:47:07 PM
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">
Title: Re: Two bugs in generating the correct label for "select" and "radio" fields
Post by: StefanSTS on September 05, 2019, 01:47:07 AM
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.

Title: Re: Two bugs in generating the correct label for "select" and "radio" fields
Post by: Milbo on September 07, 2019, 08:32:36 AM
Thank you arcturus, is fixed.
Title: Re: Two bugs in generating the correct label for "select" and "radio" fields
Post by: man.of.earth on September 08, 2019, 18:38:28 PM
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 :)
Title: Re: Two bugs in generating the correct label for "select" and "radio" fields
Post by: Milbo on September 20, 2019, 13:16:58 PM
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.
Title: Re: Two bugs in generating the correct label for "select" and "radio" fields
Post by: stAn99 on September 20, 2019, 13:50:41 PM
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


Title: Re: Two bugs in generating the correct label for "select" and "radio" fields
Post by: Milbo on September 25, 2019, 14:25:48 PM
fixed in vm3.6.2, the _field is added to the id only
Title: Re: Two bugs in generating the correct label for "select" and "radio" fields
Post by: man.of.earth on September 25, 2019, 18:34:57 PM
Great!  :)