Jump to content

Select in HelperForm


herwaldi
 Share

Recommended Posts

Posted (edited)

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)

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More