Skip to content

Commit

Permalink
feat: related PrestaShop#35591 - bug3 : dynamic form fields based on …
Browse files Browse the repository at this point in the history
…attribute type for creating new values
  • Loading branch information
mattgoud committed Apr 25, 2024
1 parent 0b383ea commit 0ff5e93
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
31 changes: 31 additions & 0 deletions admin-dev/themes/new-theme/js/pages/attribute/form/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,34 @@ $(() => {

new window.prestashop.component.ChoiceTree(AttributeFormMap.attributeShopAssociationInput).enableAutoCheckChildren();
});

document.addEventListener('DOMContentLoaded', () => {
const attributeGroupSelect: HTMLElement | null = document.querySelector('#attribute_attribute_group');
const attributeColorRow: HTMLElement | null = document.querySelector('.js-attribute-type-color-form-row');
const attributeTextureRow: HTMLElement | null = document.querySelector('.js-attribute-type-texture-form-row');

const attributeGroupSelectValue = (attributeGroupSelect as HTMLInputElement | null)?.value;

if (attributeColorRow && attributeTextureRow) {
if (attributeGroupSelectValue === '2') {
attributeColorRow.style.display = 'flex';
attributeTextureRow.style.display = 'flex';
} else {
attributeColorRow.style.display = 'none';
attributeTextureRow.style.display = 'none';
}
}
attributeGroupSelect?.addEventListener('change', () => {
const NewattributeGroupSelectValue = (attributeGroupSelect as HTMLInputElement | null)?.value;

if (attributeColorRow && attributeTextureRow) {
if (NewattributeGroupSelectValue === '2') {
attributeColorRow.style.display = 'flex';
attributeTextureRow.style.display = 'flex';
} else {
attributeColorRow.style.display = 'none';
attributeTextureRow.style.display = 'none';
}
}
});
});
20 changes: 16 additions & 4 deletions src/PrestaShopBundle/Form/Admin/Sell/Catalog/AttributeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,29 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'help' => $this->trans('Your internal name for this attribute.', 'Admin.Catalog.Help')
. ' ' . $this->trans('Invalid characters:', 'Admin.Notifications.Info')
. ' ' . TypedRegexValidator::CATALOG_CHARS,
]);
])

if ($hasAttributeGroupId === true && $attributeGroup->group_type === AttributeGroupType::ATTRIBUTE_GROUP_TYPE_COLOR) {
$builder->add('color', ColorType::class, [
->add('color', ColorType::class, [
'label' => $this->trans('Color', 'Admin.Global'),
'row_attr' => array(
'class' => 'js-attribute-type-color-form-row'),
'required' => false,
])->add('texture', FileType::class, [
'label' => $this->trans('Texture', 'Admin.Global'),
'row_attr' => array(
'class' => 'js-attribute-type-texture-form-row'),
'required' => false,
]);
}

// if ($hasAttributeGroupId === true && $attributeGroup->group_type === AttributeGroupType::ATTRIBUTE_GROUP_TYPE_COLOR) {
// $builder->add('color', ColorType::class, [
// 'label' => $this->trans('Color', 'Admin.Global'),
// 'required' => false,
// ])->add('texture', FileType::class, [
// 'label' => $this->trans('Texture', 'Admin.Global'),
// 'required' => false,
// ]);
// }

if ($this->multistoreFeature->isUsed()) {
$builder->add('shop_association', ShopChoiceTreeType::class, [
Expand Down

0 comments on commit 0ff5e93

Please sign in to comment.