Jump to content

Select in HelperForm


herwaldi

Recommended Posts

Hello everyone,

How to select an active option in my module?

checked options dont work :(

 

        return array(
            'form' => array(
                'legend' => array(
                    'title' => $this->l('Choose products'),
                    'icon' => 'icon-th-large',
                ),
                'input' => array(
                    array(
                        'type' => 'select',
                        'label' => $this->l('Products available with a gift'),
                        'name' => 'selectProductsField',
                        'class' => 'selectProducts',
                        'required' => false,
                        'col' => 5,
                        'multiple' => true,
                        'options' => array(
                            'query' => ProductGiftProduct::getProducts(true),
                            'id' => 'id_product',
                            'name' => 'name',
                            'checked' => 597,
                        )
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );

 

Edited by herwaldi
wrong code (see edit history)
Link to comment
Share on other sites

you should pass the value using "fields_value" as below

 

$helper->tpl_vars = array(
	'uri' => $this->getPathUri(),
	'fields_value' => $this->getConfigFieldsValues(),
	'languages' => $this->context->controller->getLanguages(),
	'id_language' => $this->context->language->id
);


here, getConfigFieldsValues should return an associative array with field name, value pair
 

function getConfigFieldsValues()
{
	return array(
		'selectProductsField' => 597
	);
}

 

  • Like 1
Link to comment
Share on other sites

13 hours ago, abdullacm said:

you should pass the value using "fields_value" as below

 

$helper->tpl_vars = array(
	'uri' => $this->getPathUri(),
	'fields_value' => $this->getConfigFieldsValues(),
	'languages' => $this->context->controller->getLanguages(),
	'id_language' => $this->context->language->id
);


here, getConfigFieldsValues should return an associative array with field name, value pair
 

function getConfigFieldsValues()
{
	return array(
		'selectProductsField' => 597
	);
}

 

thank you ❤️

  • Haha 1
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...