Jump to content

Select field set default selected in admin product


rvkvino
 Share

Recommended Posts

Hello,

I have an issue on set default selected value in admin product page. I have created one new field to select the value to the product and it's storing the values into tables but while I edit and check first value only selected default, which ever I have selected and stored value not showing with selected.

I have an code like below in src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/Panels/pricing.html.twig

<div class="col-md-6">
                <label class="form-control-label">{{ pricingForm.purity.vars.label }}</label>
                {{ form_errors(pricingForm.purity) }}
                {{ form_widget(pricingForm.purity) }}
              </div>

And src/PrestaShopBundle/Form/Admin/Product/ProductPrice.php

$this->purity_types = [
                $this->translator->trans('22 Ct', [], 'Admin.Global') => '22',
                $this->translator->trans('18 Ct', [], 'Admin.Global') => '18',
            ];

->add(
                'purity',
                FormType\ChoiceType::class,
                [
                    'choices' => $this->purity_types,
                    'choice_attr' => function ($val) {
                        return [
                            'data-rates' => $val,
                            'data-computation-method' => $val,
                        ];
                    },
                    'attr' => [
                        'data-toggle' => 'select2',
                        'data-minimumResultsForSearch' => '7',
                    ],
                    'label' => $this->translator->trans('Purity', [], 'Admin.Catalog.Feature'),
                ]
            )

But it's only displaying default value not setting selected = 'selected ' on option, I don't know where to set it. Please help anyone to solve this issue.

Share this post


Link to post
Share on other sites

  • 1 year later...

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