Skip to content

Commit

Permalink
Ref #215: hide/show bank selector if payment needs it in membership e…
Browse files Browse the repository at this point in the history
…dition&create forms
  • Loading branch information
LucileDT committed Jul 16, 2020
1 parent 2cc9d44 commit f40ca95
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
25 changes: 25 additions & 0 deletions public/javascript/Membership/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ var selectedPeopleCount = 0;
// -- Document ready listener -- //
///////////////////////////////////
$(document).ready(function() {
// Show bank select if payment type needs it
let isBankNeeded = $("option:selected", '#app_membership_bank').data('is-bank-needed') === undefined ? false : true;
if (isBankNeeded)
{
removeDisplayNone('payment-bank');
}
else
{
addDisplayNone('payment-bank');
}

// -- Declaration of the event listeners -- //
$('#app_membership_paymentAmount').keyup(function() {
updatePaymentAmount();
Expand All @@ -32,6 +43,20 @@ $(document).ready(function() {
}
});

// Show/hide bank select picker depending on payment type
$('#app_membership_paymentType').change(function(event) {
let isBankNeeded = $("option:selected", this).data('is-bank-needed') === undefined ? false : true;
console.debug(isBankNeeded);
if (isBankNeeded)
{
removeDisplayNone('payment-bank');
}
else
{
addDisplayNone('payment-bank');
}
});

$('#app_membership_newMember').change(function() {
let selectedPeopleId = $(this).val();

Expand Down
8 changes: 7 additions & 1 deletion src/Form/MembershipFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'expanded' => false,
'attr' => [
'autocomplete' => 'off',
]
],
'choice_attr' => function(PaymentType $paymentType)
{
return [
'data-is-bank-needed' => $paymentType->isBankneeded(),
];
},
]);

$builder->add('membershipAmount', MoneyType::class, [
Expand Down
2 changes: 1 addition & 1 deletion templates/Membership/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</div>
{{ form_row(membership_edit_form.payer)}}
{{ form_row(membership_edit_form.paymentType)}}
<div id="payment-bank" class="form-group">
<div id="payment-bank" class="form-group d-none">
{{ form_row(membership_edit_form.bank)}}
</div>
{{ form_row(membership_edit_form.paymentDate_received)}}
Expand Down

0 comments on commit f40ca95

Please sign in to comment.