Jump to content

[SOLVED] Select in HelperForm


gr4devel

Recommended Posts

Hi community :).

I'm trying to reimplement my modules backoffice utilizing the new Helper functions of PS 1.5.

I've read the documentation but still I have to get used to these functions and their parameters and in particular to the ones pertaining to the select box options.

I can't get the right values displayed in the select box options.

The $features variable is just an array or array in which the inner one (i.e. the row) is composed by many fields and "id_feature" is one of them.

Actually I want to use this last as the value and the "name" field as the text of the option.

 

$fields_form[0]['form'] = array(
  'legend' => array(
	'title' => $this->l('Settings'),
	'image' => $this->_path.'logo.gif'
  ),
  'input' => array(
	array(
	  'type' => 'select',
	  'label' => $this->l('My field:'),
	  'name' => 'myfield',
	  'required' => true,
	  'options' => array(
		'query' => $features,
		'id' => 'id_feature'
	  )
	)
  ),
  'submit' => array(
	'title' => $this->l('Save'),
	'class' => 'button'
  )
);

 

Thanks in advance to anyone would help me :).

Edited by g11111g (see edit history)
Link to comment
Share on other sites

Ok I was able to get what I need by adding to the 'options' array the 'name' entry and associating it with the actual field of the $features array (i.e. 'name').

Here's just the bit of code that I've changed:

 

  'input' => array(
	array(
	  'type' => 'select',
	  'label' => $this->l('Product vintage feature:'),
	  'name' => 'vintageFeature',
	  'required' => true,
	  'options' => array(
		'query' => $features,
		'id' => 'id_feature',
		'name' => 'name'
	  )
	)
  ),

 

Sorry for the bother and hopes that this will help someone who face the same problem :).

Edited by g11111g (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...
  • 1 month later...
  • 7 months later...
  • 6 months later...
  • 5 weeks later...
  • 10 months later...

Up,

 

Did you find a solution to set the selected value ?

 

I need it too ...

 

Cheer

 

Ok I was able to get what I need by adding to the 'options' array the 'name' entry and associating it with the actual field of the $features array (i.e. 'name').

Here's just the bit of code that I've changed:

 

	  'input' => array(
		array(
		  'type' => 'select',
		  'label' => $this->l('Product vintage feature:'),
		  'name' => 'vintageFeature',
		  'required' => true,
		  'options' => array(
			'query' => $features,
			'id' => 'id_feature',
			'name' => 'name'
		  )
		)
	  ),
Sorry for the bother and hopes that this will help someone who face the same problem smile.png.

 

 

Here is the solution for selected value (I continue the example above):

 

$this->fields_value['vintageFeature'] = $default_id_feature; 
// Here: 
// 'vintageFeature' is the 'name' of your input
// $default_id_feature is the 'id' of the default value
  • Like 2
Link to comment
Share on other sites

  • 2 years later...
On 06/10/2015 at 3:09 PM, olesho said:

 

 

Here is the solution for selected value (I continue the example above):

 


$this->fields_value['vintageFeature'] = $default_id_feature; 
// Here: 
// 'vintageFeature' is the 'name' of your input
// $default_id_feature is the 'id' of the default value

 

Hello,

This not work for multiple select.

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...