Jump to content
rvkvino

Select field set default selected in admin product

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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