VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: Gruz on March 24, 2012, 22:18:35 PM

Title: Is a list custom field bug - cannot change the value if once selected
Post by: Gruz on March 24, 2012, 22:18:35 PM
J.2.5.3
VM SVN, 2.0.3.G

I add a custom field.
(http://static.xscreenshot.com/2012/03/24/22/screen_d47333cfaac417dd52be062e4c468fa0) (http://view.xscreenshot.com/d47333cfaac417dd52be062e4c468fa0)

Next I add it to a product and can select an item

(http://static.xscreenshot.com/2012/03/24/23/screen_396e814de695963068a78e98df4b2c73) (http://view.xscreenshot.com/396e814de695963068a78e98df4b2c73)

I press save and cannot change the item anymore:

(http://static.xscreenshot.com/2012/03/24/23/screen_60e48e252cb4722d23747e71a4abbda6) (http://view.xscreenshot.com/60e48e252cb4722d23747e71a4abbda6)

Solution

administrator/components/com_virtuemart/models/customfields.php

Change

$values = explode(';',$field->custom_value);

foreach ($values as $key => $val){
$options[] = array( 'value' => $val ,'text' =>$val);
}

return JHTML::_('select.genericlist', $options,'field['.$row.'][custom_value]').'</td><td>'.$priceInput;



to


$values = explode(';',$field->value);

$selected = null;
foreach ($values as $key => $val){
if ($field->custom_value == $val) {
$selected = $val;
}
if (empty ($val)) {
$options[] = array( 'value' => $val ,'text' =>JText::_('COM_VIRTUEMART_NONE'));
continue;
}
$options[] = array( 'value' => $val ,'text' =>$val);
}

return JHTML::_('select.genericlist', $options,'field['.$row.'][custom_value]',null,'value','text',$selected).'</td><td>'.$priceInput;



Result:

(http://static.xscreenshot.com/2012/03/24/23/screen_29f69f71d4aa5cc6d1898fa38fbfa442) (http://view.xscreenshot.com/29f69f71d4aa5cc6d1898fa38fbfa442)

Diff:


Index: administrator/components/com_virtuemart/models/customfields.php
===================================================================
--- administrator/components/com_virtuemart/models/customfields.php (revision 5705)
+++ administrator/components/com_virtuemart/models/customfields.php (working copy)
@@ -332,13 +332,21 @@

if ($field->is_list) {
$options = array();
- $values = explode(';',$field->custom_value);
+ $values = explode(';',$field->value);

+ $selected = null;
foreach ($values as $key => $val){
+ if ($field->custom_value == $val) {
+ $selected = $val;
+ }
+ if (empty ($val)) {
+ $options[] = array( 'value' => $val ,'text' =>JText::_('COM_VIRTUEMART_NONE'));
+ continue;
+ }
$options[] = array( 'value' => $val ,'text' =>$val);
}

- return JHTML::_('select.genericlist', $options,'field['.$row.'][custom_value]').'</td><td>'.$priceInput;
+ return JHTML::_('select.genericlist', $options,'field['.$row.'][custom_value]',null,'value','text',$selected).'</td><td>'.$priceInput;
} else {

switch ($field->field_type) {