VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: AnthonyWang on February 28, 2016, 09:37:18 AM

Title: selectlist function
Post by: AnthonyWang on February 28, 2016, 09:37:18 AM
Could anyone can give me a customfield multiple select example in plugin?
I tried many solution on it 6days,until now still can't get it work,
please help


$label_options = array('0'=>'Label1','1'=>'Label2');
$html .= VmHTML::row('selectList',
'VMCUSTOM_INFO_LABEL',
'customfield_params['.$row.'][custom_label[]]',
array_values($label_options),
$label_options, //  $custom_label,?
'10',
'multiple="multiple"');

Title: Re: selectlist function
Post by: Studio 42 on March 01, 2016, 13:13:15 PM
YOu can use you standard html and Joomla select list, if vmHtml row do not work.
here  is the function with parameters VmHTML::row('selectList','LABEL',$name, $values, $defaultValues, $size, $multiple)
Title: Re: selectlist function
Post by: AnthonyWang on March 01, 2016, 14:31:28 PM
Studio,awesome,
but still a problem when i tried this code,
in productedit page,i can't save select option what i select
is this "$label_options" issue?
when i check db, the parameters is empty custom_label=""|



$label_options = array('a'=>'Label1','b'=>'Label2',xxxxxxxxxxxxxxxxxxxxxxxxxxxxx);
$html .= VmHTML::row('selectList','LABEL','customfield_params['.$row.'][custom_label]', $label_options,  $label_options, '10', 'multiple="multiple"',[color=red]false[/color]);

PS: if use multiple select seem shouldn't have a default value?

Title: Re: selectlist function
Post by: PRO on March 01, 2016, 18:52:05 PM
Quote from: AnthonyWang on March 01, 2016, 14:31:28 PM
Studio,awesome,
but still a problem when i tried this code,
in productedit page,i can't save select option what i select
is this "$label_options" issue?
when i check db, the parameters is empty custom_label=""|



$label_options = array('a'=>'Label1','b'=>'Label2',xxxxxxxxxxxxxxxxxxxxxxxxxxxxx);
$html .= VmHTML::row('selectList','LABEL','customfield_params['.$row.'][custom_label]', $label_options,  $label_options, '10', 'multiple="multiple"',[color=red]false[/color]);

PS: if use multiple select seem shouldn't have a default value?



does anything save?

do you have it in varstopush?


for example
      $varsToPush = array(
         'modifier'=>array('','string'),
         'label'=>array('','string'),
         'disc'=>array('','string'),
         'discmod'=>array('','string'),
         'under_disc'=>array('','string'),
         'under_discmod'=>array('','string'),
         'qdisc1'=>array('','string'),
         'qdisc2'=>array('','string'),
         'qdisc3'=>array('','string')
      );

      $this->setConfigParameterable('customfield_params',$varsToPush);

   }

at the top of your plugin file?
Title: Re: selectlist function
Post by: AnthonyWang on March 01, 2016, 20:12:34 PM
Hello PRO,
Yes,i had,in first time i create plugin,
$varsToPush = array(
'custom_limit'=>array('', 'int'),
'custom_label'=>array('','string')
);

$this->setConfigParameterable('customfield_params',$varsToPush);

Title: Re: selectlist function
Post by: PRO on March 01, 2016, 20:55:16 PM
what version are you using?

and it can be an xml issue.

Title: Re: selectlist function
Post by: AnthonyWang on March 01, 2016, 21:17:41 PM
Hello PRO,
i'm using
Joomla 3.4.8 / Virtuemart 3.0.12 / Php 5.4
Title: Re: selectlist function
Post by: PRO on March 01, 2016, 22:07:29 PM
can you get anything to save?

that happened to me before(nothing saved), and I had to re-do the xml file.

Title: Re: selectlist function
Post by: AnthonyWang on March 01, 2016, 22:23:34 PM
Hello PRO,
nothing saved,but i found a possible problem ten min. ago,and found a solution,
it's xml issue, i'll try it tomorrow,If that solution is the right way,i'll report it here.
thanks!

Best Regards.,
Title: Re: selectlist function
Post by: Studio 42 on March 02, 2016, 00:49:19 AM
Hi,
And i think the problem is your fieldname
$fieldname = 'customfield_params['.$row.'][custom_label][]';

ELSE NATIVE JOOMLA AND HTML
<tr>
<td><?php echo vmText::_(''VMCUSTOM_INFO_LABEL''?></td>
<td><?php echo JHTML::_('select.genericlist',$options,$fieldname,'multiple="multiple"','value','text',$default?></td>
</tr>
Title: Re: selectlist function
Post by: AnthonyWang on March 02, 2016, 01:30:45 AM
Hello Studio,
Awesome! you save my time!it's seems store data in db now,really appreciate!
but there is a issue,in productedit page,the select box is empty,could you tell me,where i can fix it?
(http://imgur.com/nvMPg6z)
Title: Re: selectlist function
Post by: Studio 42 on March 02, 2016, 01:57:35 AM
If you use Joomla list, you need to conform to generic list options.
Eg.
<?php 
$fieldname 
'customfield_params['.$row.'][custom_label][]';
$options = array();
foreach(
$label_options as $key=>$value) {
$options[] = JHTML::_('select.option'$key$value);
}
$html .='<tr>
<td>'
vmText::_(''VMCUSTOM_INFO_LABEL'').'</td>
<td>'
JHTML::_('select.genericlist',$options,$fieldname,'multiple="multiple"','value','text',$default) .'</td>
</tr>'
;

Title: Re: selectlist function
Post by: AnthonyWang on March 02, 2016, 02:03:02 AM
Thanks Studio,i'll try it later