diff --git a/assets/styles/components/forms.css b/assets/styles/components/forms.css index c607a36..f4a34f5 100644 --- a/assets/styles/components/forms.css +++ b/assets/styles/components/forms.css @@ -21,7 +21,7 @@ label.required:after { @apply border-red-500; } -input[disabled], -input[readonly] { - @apply cursor-not-allowed; +input[readonly], +select[readonly] { + @apply pointer-events-none; } diff --git a/src/Form/ParticipantType.php b/src/Form/ParticipantType.php index 4870b05..ea288d9 100644 --- a/src/Form/ParticipantType.php +++ b/src/Form/ParticipantType.php @@ -149,7 +149,7 @@ class ParticipantType extends AbstractType number_format($price, 2, ',', '.') ); }, - 'choice_attr' => function (?Service $service) { + 'choice_attr' => function (?Service $service) use ($options) { $attributes = [ 'data-booking-target' => 'field', 'data-action' => 'booking#toggle', @@ -158,24 +158,28 @@ class ParticipantType extends AbstractType // forcibly select mandatory services if (true === $service->mandatory) { $attributes['checked'] = true; - $attributes['disabled'] = true; + $attributes['readonly'] = true; $attributes['class'] = 'text-pink'; $attributes['tooltip'] = 'Diese Leistung ist nicht abwählbar'; } // disable selection of services only available in booking data if (Service::SOURCE_BOOKING === $service->source) { - $attributes['disabled'] = true; $attributes['class'] = 'text-pink'; } // disable selection of services that are unavailable according to their status if (Service::STATUS_BLOCKED === $service->status) { $attributes['checked'] = false; - $attributes['disabled'] = true; + $attributes['readonly'] = true; $attributes['tooltip'] = 'Diese Leistung ist derzeit leider nicht buchbar'; } + if (false === $options['additional_services_mutable']) { + $attributes['readonly'] = true; + $attributes['tooltip'] = 'Diese Leistung kann nicht mehr geändert werden'; + } + return $attributes; }, 'choice_filter' => function (?Service $service) use ($participantData) { @@ -233,6 +237,19 @@ class ParticipantType extends AbstractType } // Transportation + $transportationChoiceAttributes = function (?Service $service) use ($options) { + $attributes = [ + 'data-booking-target' => 'field', + 'data-action' => 'select-toggle#toggle booking#toggle', + 'data-select-toggle-value' => $service->subType, + ]; + if (false === $options['transportation_services_mutable']) { + $attributes['readonly'] = true; + $attributes['tooltip'] = 'Diese Leistung kann nicht mehr geändert werden'; + } + + return $attributes; + }; $form ->add('transportationServiceTo', ChoiceType::class, [ ...$commonChoiceFieldOptions, @@ -240,13 +257,7 @@ class ParticipantType extends AbstractType 'required' => true, 'multiple' => false, 'choices' => $options['selectable_transportation_services_to'], - 'choice_attr' => function (?Service $service) { - return [ - 'data-booking-target' => 'field', - 'data-action' => 'select-toggle#toggle booking#toggle', - 'data-select-toggle-value' => $service->subType, - ]; - }, + 'choice_attr' => $transportationChoiceAttributes, ]) ->add('transportationServiceFro', ChoiceType::class, [ ...$commonChoiceFieldOptions, @@ -254,13 +265,7 @@ class ParticipantType extends AbstractType 'required' => true, 'multiple' => false, 'choices' => $options['selectable_transportation_services_fro'], - 'choice_attr' => function (?Service $service) { - return [ - 'data-booking-target' => 'field', - 'data-action' => 'select-toggle#toggle booking#toggle', - 'data-select-toggle-value' => $service->subType, - ]; - }, + 'choice_attr' => $transportationChoiceAttributes, ]) ; @@ -287,6 +292,17 @@ class ParticipantType extends AbstractType number_format($price, 2, ',', '.') ); }, + 'choice_attr' => function (?Pickup $pickup) use ($options) { + $attributes = []; + if (false === $options['pickups_mutable']) { + $attributes['readonly'] = true; + } + + return $attributes; + }, + 'attr' => [ + 'readonly' => false === $options['pickups_mutable'], + ] ]); }) ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) { diff --git a/templates/forms.html.twig b/templates/forms.html.twig index 0f63102..b15fd66 100644 --- a/templates/forms.html.twig +++ b/templates/forms.html.twig @@ -69,9 +69,6 @@ {%- if errors|length -%} {%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-checkbox--has-error' }) -%} {%- endif -%} - {%- if attr.disabled is defined and attr.disabled == true -%} - {%- set attr = attr|merge({'class': attr.class|default('') ~ ' cursor-not-allowed' }) -%} - {%- endif -%} {%- set tooltip = null -%} {%- if attr.tooltip is defined -%} {%- set tooltip = attr.tooltip -%} @@ -87,9 +84,6 @@ {%- if errors|length -%} {%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-radio--has-error' }) -%} {%- endif -%} - {%- if attr.disabled is defined and attr.disabled == true -%} - {%- set attr = attr|merge({'class': attr.class|default('') ~ ' cursor-not-allowed' }) -%} - {%- endif -%} {%- set tooltip = null -%} {%- if attr.tooltip is defined -%} {%- set tooltip = attr.tooltip -%} @@ -101,7 +95,7 @@ {%- endblock radio_widget -%} {% block checkbox_row %} -
+
{{ form_widget(form) }}
@@ -129,9 +123,6 @@ {% else %} {{ parent() }} {% endif %} - {%- if disabled is defined and disabled == true -%} - - {%- endif -%} {%- endblock choice_widget_collapsed -%} {%- block choice_widget_expanded -%}