Skip to content

Commit

Permalink
Fixed SEPAExport form type
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtronics committed Jan 24, 2025
1 parent e90acd0 commit 1a42fae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace App\Controller;
namespace App\Controller\Admin;

use App\Entity\BankAccount;
use App\Entity\PaymentOrder;
Expand All @@ -35,7 +35,7 @@
* @see \App\Tests\Controller\ExportControllerTest
*/
#[Route(path: '/admin/payment_order')]
final class ExportController extends AbstractController
final class SEPAExportController extends AbstractController
{
public function __construct(
private readonly PaymentOrdersSEPAExporter $sepaExporter,
Expand Down
30 changes: 14 additions & 16 deletions src/Form/SepaExportType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Bic;
use Symfony\Component\Validator\Constraints\Iban;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\When;

class SepaExportType extends AbstractType
{
Expand All @@ -50,37 +52,33 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'required' => false,
'class' => BankAccount::class,
'attr' => [
'class' => 'field-association select2',
//Define the handler to enable/disable the other fields (this is a bit hacky though)...
'onchange' => 'onPresetChange(this);',
'data-mode-manual' => true,
'class' => 'field-association',
'data-ea-widget' => 'ea-autocomplete',
],
'placeholder' => 'sepa_export.bank_account.placeholder',
'choice_label' => fn(BankAccount $account): string => $account->getExportAccountName().' ['.$account->getIban().']',
]);

$builder->add('name', TextType::class, [
'label' => 'sepa_export.name.label',
'attr' => [
'data-manual-input' => true,
'data-mode-manual' => true,
],
'required' => false,
'constraints' => [new When("this.getParent().getData()['mode'] === 'manual' and this.getParent().getData()['bank_account'] === null", new NotBlank())],
]);
$builder->add('iban', TextType::class, [
'label' => 'sepa_export.iban.label',
'constraints' => [new Iban()],
'attr' => [
'data-manual-input' => true,
'data-mode-manual' => true,
'constraints' => [
new Iban(),
new When("this.getParent().getData()['mode'] === 'manual' and this.getParent().getData()['bank_account'] === null", new NotBlank())
],
'required' => false,
]);
$builder->add('bic', TextType::class, [
'label' => 'sepa_export.bic.label',
'constraints' => [new Bic()],
'attr' => [
'data-manual-input' => true,
'data-mode-manual' => true,
'constraints' => [
new Bic(),
new When("this.getParent().getData()['mode'] === 'manual' and this.getParent().getData()['bank_account'] === null", new NotBlank())
],
'required' => false,
]);

$builder->add('submit', SubmitType::class, [
Expand Down
34 changes: 0 additions & 34 deletions templates/admin/payment_order/export/export.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,6 @@
{% block page_title %}{% trans %}sepa_export.title{% endtrans %}{% endblock %}

{% block page_content %}

<script>
function onModeChange() {
if (this.value === "manual") {
$("[data-mode-manual]").removeAttr("disabled");
} else {
$("[data-mode-manual]").attr("disabled", "1");
}
}
$(document).ready(function() {
$('.select2').select2();
{# Disable/Enable fields for manual mode if needed #}
$('input[type=radio][name="sepa_export[mode]"]').change(onModeChange);
$("[data-mode-manual]").attr("disabled", "1");
})
</script>

<script>
{# Disable/Enable fields for manual input if needed. #}
function onPresetChange(element) {
if (element.value === "") {
$("[data-manual-input]").removeAttr("disabled");
} else {
$("[data-manual-input]").attr("disabled", "1");
}
}
</script>

<h5>{% trans %}sepa_export.title2{% endtrans %}</h5>
<p class="text-muted">{% trans %}sepa_export.help{% endtrans %}</p>

Expand Down

0 comments on commit 1a42fae

Please sign in to comment.