Skip to content

Commit

Permalink
RSYS-3071: Fixed bugs: error label, related checkbox (#68)
Browse files Browse the repository at this point in the history
* RSYS-3071: Fixed bugs: error label, related checkbox

* Remove empty line

* After CR
  • Loading branch information
lucasOsti authored Dec 15, 2020
1 parent 35ae45b commit 3c808e4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/bundle/Resources/public/js/scenarios-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
const container = event.currentTarget.closest('.ez-field-edit__data-group-items--action-checkbox-container');
const inputs = container.querySelectorAll('.ez-personalization-base-item__input-field');

if (dataset.hasOwnProperty('relatedId')) {
doc.querySelectorAll(`[related="${dataset.relatedId}"]`).forEach((relatedCheckbox) => {
if (dataset.relatedId) {
doc.querySelectorAll(`[data-related="${dataset.relatedId}"]`).forEach((relatedCheckbox) => {
relatedCheckbox.disabled = !checked;

if (!checked) {
relatedCheckbox.checked = false;
}
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/bundle/Resources/public/scss/_base-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
}
}

.ez-field-edit__error {
margin-top: 0;
}

&--edit {
.ez-field-edit {
padding: calculateRem(24px) 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,8 @@
</section>
{{ form_end(scenario_form) }}
{% endblock %}

{% block javascripts %}
{{ parent() }}
{{ encore_entry_script_tags('ezplatform-personalization-scenarios-edit-js', null, 'ezplatform') }}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{% use 'bootstrap_4_layout.html.twig' %}

{%- block form_errors -%}
{% block form_errors %}
{%- if errors|length > 0 -%}
{%- for error in errors -%}
<em class="ez-field-edit__error">{{ error.message }}</em>
{%- endfor -%}
{%- endif -%}
{%- endblock -%}
{% endblock form_errors %}

{% block form_label_errors %}{% endblock form_label_errors %}

{% block form_row -%}
{% set wrapper_class = 'ez-field-edit' %}
Expand All @@ -23,17 +25,20 @@
{% set label_wrapper_attr = label_wrapper_attr|default({})|merge({'class': (label_wrapper_attr.class|default('') ~ 'ez-field-edit__label-wrapper')|trim}) %}
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' ez-field-edit__label')|trim}) %}
{% set widget_wrapper_attr = widget_wrapper_attr|default({})|merge({'class': (widget_wrapper_attr.class|default('') ~ ' ez-field-edit__data')|trim}) %}
{% set attr = attr|merge({'class': (attr.class|default('') ~ ' ez-personalization-base-item__input-field ez-data-source__input')|trim}) %}

<div {% with { attr: wrapper_attr } %}{{ block('attributes') }}{% endwith %}>
<div{% with { attr: label_wrapper_attr } %}{{ block('attributes') }}{% endwith %}>
{{ block('form_label') }}
{{ block('form_errors') }}
</div>
<div{% with { attr: widget_wrapper_attr } %}{{ block('attributes') }}{% endwith %}>
{{- form_widget(form, {'attr': attr}) -}}
<div class="ez-data-source">
{{- form_widget(form, {'attr': attr}) -}}
{{ block('form_errors') }}
</div>
</div>
</div>
{%- endblock %}
{% endblock %}

{% block _scenario_user_profile_settings_widget %}
{% for child in form.children %}
Expand Down Expand Up @@ -95,8 +100,8 @@
</div>
{% endblock %}

{% block _scenario_user_profile_settings_user_attribute_name_widget %}
{% set relatedTo = form.parent.exclude_repeated_recommendations.children.enabled %}
{% block _scenario_user_profile_settings_user_attribute_name_widget %}
{% set relatedTo = form.parent.boost_item.children.enabled %}

<div class="ez-field-edit__data-group-items ez-field-edit__data-group-items--inline ez-field-edit__data-group-items--action-checkbox-container">
{{ form_widget(form.enabled, {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Form/Type/OptionalTextType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('enabled', CheckboxType::class, [
'label' => false,
'attr' => [
'related' => $builder->getOption('data-related'),
'data-related' => $builder->getOption('data-related'),
'class' => $builder->getOption('class'),
],
])
Expand All @@ -40,11 +40,11 @@ public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => OptionalTextData::class,
'related' => null,
'data-related' => null,
'class' => null,
'value_label' => null,
])
->setAllowedTypes('related', ['null', 'string'])
->setAllowedTypes('data-related', ['null', 'string'])
->setAllowedTypes('class', ['null', 'string'])
->setAllowedTypes('value_label', ['null', 'string']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'required' => false,
'label' => $this->translator->trans(/** @Desc("Do not recommend if price unknown") */ 'scenario.commerce_settings.do_not_recommend_if_price_unknown', [], 'ibexa_personalization'),
'attr' => [
'related' => self::HTML_CLASS_EXCLUDE_MINIMAL_ITEM_PRICE,
'data-related' => self::HTML_CLASS_EXCLUDE_MINIMAL_ITEM_PRICE,
],
])
->add('exclude_already_purchased', CheckboxType::class, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
])
->add('user_attribute_name', OptionalTextType::class, [
'required' => false,
'related' => self::HTML_CLASS_BOOST_ITEM,
'data-related' => self::HTML_CLASS_BOOST_ITEM,
'value_label' => $this->translator->trans(/** @Desc("User attribute has different name") */ 'scenario.user_profile_settings.user_attribute_has_different_name', [], 'ibexa_personalization'),
])
->addEventSubscriber(new ScenarioUserSettingsSubscriber())
Expand Down

0 comments on commit 3c808e4

Please sign in to comment.