|
| 1 | +<template> |
| 2 | + <form |
| 3 | + method="post" |
| 4 | + class="wmde-banner-sub-form wmde-banner-sub-form-donation" |
| 5 | + @submit.prevent="validate" |
| 6 | + > |
| 7 | + <fieldset class="wmde-banner-form-field-group"> |
| 8 | + <legend class="wmde-banner-form-field-group-legend">{{ $translate( 'intervals-header' ) }}</legend> |
| 9 | + <SelectGroup |
| 10 | + :field-name="'select-interval'" |
| 11 | + :selectionItems="formItems.intervals" |
| 12 | + :isValid="isValidOrUnset( intervalValidity )" |
| 13 | + :errorMessage="$translate( 'no-interval-message' )" |
| 14 | + v-model:inputValue="interval" |
| 15 | + :disabledOptions="disabledIntervals" |
| 16 | + /> |
| 17 | + </fieldset> |
| 18 | + |
| 19 | + <fieldset class="wmde-banner-form-field-group"> |
| 20 | + <legend class="wmde-banner-form-field-group-legend">{{ $translate( 'amounts-header' ) }}</legend> |
| 21 | + <SelectGroup |
| 22 | + fieldName="select-amount" |
| 23 | + :selectionItems="amountsForFormItems" |
| 24 | + :isValid="isValidOrUnset( amountValidity )" |
| 25 | + :errorMessage="$translate( amountValidityMessageKey( amountValidity ) )" |
| 26 | + v-model:inputValue="selectedAmount" |
| 27 | + > |
| 28 | + <SelectCustomAmount |
| 29 | + fieldName="select-amount" |
| 30 | + v-model:inputValue="customAmount" |
| 31 | + @focus="clearSelectedAmount" |
| 32 | + @blur="formatCustomAmount" |
| 33 | + :placeholder="$translate( customAmountPlaceholderKey )" |
| 34 | + /> |
| 35 | + </SelectGroup> |
| 36 | + </fieldset> |
| 37 | + |
| 38 | + <fieldset class="wmde-banner-form-field-group"> |
| 39 | + <legend class="wmde-banner-form-field-group-legend">{{ $translate( 'payments-header' ) }}</legend> |
| 40 | + <SelectGroup |
| 41 | + :field-name="'select-payment-method'" |
| 42 | + :selectionItems="formItems.paymentMethods" |
| 43 | + :isValid="isValidOrUnset( paymentMethodValidity )" |
| 44 | + :errorMessage="$translate( 'no-payment-type-message' )" |
| 45 | + v-model:inputValue="paymentMethod" |
| 46 | + :disabledOptions="disabledPaymentMethods" |
| 47 | + > |
| 48 | + <template #select-group-label="{ label, slotName }: any"> |
| 49 | + <slot :name="'label-' + slotName" :label="label"/> |
| 50 | + </template> |
| 51 | + <SmsBox> |
| 52 | + <template #sms-icon> |
| 53 | + <slot name="sms-icon"/> |
| 54 | + </template> |
| 55 | + </SmsBox> |
| 56 | + </SelectGroup> |
| 57 | + </fieldset> |
| 58 | + |
| 59 | + <div class="wmde-banner-form-button-container"> |
| 60 | + <slot name="button"> |
| 61 | + <MainDonationFormButtonMultiStep/> |
| 62 | + </slot> |
| 63 | + <button v-if="!isFormValid && showErrorScrollLink" class="wmde-banner-form-button-error"> |
| 64 | + {{ $translate( 'global-error' ) }} |
| 65 | + </button> |
| 66 | + </div> |
| 67 | + </form> |
| 68 | +</template> |
| 69 | + |
| 70 | +<script lang="ts"> |
| 71 | +// All form components must have names |
| 72 | +export default { |
| 73 | + name: 'MainDonationFormChangesAmountOptions' |
| 74 | +}; |
| 75 | +</script> |
| 76 | +<script setup lang="ts"> |
| 77 | +
|
| 78 | +import { inject, ref } from 'vue'; |
| 79 | +import SelectGroup from '@src/components/DonationForm/SubComponents/SelectGroup.vue'; |
| 80 | +import { DonationFormItems } from '@src/utils/FormItemsBuilder/DonationFormItems'; |
| 81 | +import SelectCustomAmount from '@src/components/DonationForm/SubComponents/SelectCustomAmount.vue'; |
| 82 | +import SmsBox from '@src/components/DonationForm/SubComponents/SmsBox.vue'; |
| 83 | +import { useFormModel } from '@src/components/composables/useFormModel'; |
| 84 | +import { newDonationFormValidator } from '@src/validation/DonationFormValidator'; |
| 85 | +import { amountValidityMessageKey } from '@src/utils/amountValidityMessageKey'; |
| 86 | +import { isValidOrUnset } from '@src/components/DonationForm/Forms/isValidOrUnset'; |
| 87 | +import { Currency } from '@src/utils/DynamicContent/formatters/Currency'; |
| 88 | +import MainDonationFormButtonMultiStep from '@src/components/DonationForm/Forms/MainDonationFormButtonMultiStep.vue'; |
| 89 | +import { FormItem } from '@src/utils/FormItemsBuilder/FormItem'; |
| 90 | +
|
| 91 | +interface Props { |
| 92 | + showErrorScrollLink?: boolean; |
| 93 | + customAmountPlaceholderKey?: string; |
| 94 | + amountsForFormItems: FormItem[]; |
| 95 | +} |
| 96 | +
|
| 97 | +withDefaults( defineProps<Props>(), { |
| 98 | + showErrorScrollLink: false, |
| 99 | + customAmountPlaceholderKey: 'custom-amount-placeholder' |
| 100 | +} ); |
| 101 | +const emit = defineEmits( [ 'submit' ] ); |
| 102 | +
|
| 103 | +const currencyFormatter = inject<Currency>( 'currencyFormatter' ); |
| 104 | +const formItems = inject<DonationFormItems>( 'formItems' ); |
| 105 | +const formModel = useFormModel(); |
| 106 | +const validator = newDonationFormValidator( formModel ); |
| 107 | +const isFormValid = ref<boolean>( true ); |
| 108 | +
|
| 109 | +const validate = (): void => { |
| 110 | + isFormValid.value = validator.validate(); |
| 111 | +
|
| 112 | + if ( isFormValid.value ) { |
| 113 | + emit( 'submit' ); |
| 114 | + } |
| 115 | +}; |
| 116 | +
|
| 117 | +const { |
| 118 | + interval, intervalValidity, disabledIntervals, |
| 119 | + selectedAmount, customAmount, numericAmount, amountValidity, |
| 120 | + paymentMethod, paymentMethodValidity, disabledPaymentMethods |
| 121 | +} = formModel; |
| 122 | +
|
| 123 | +const clearSelectedAmount = (): void => { |
| 124 | + selectedAmount.value = ''; |
| 125 | +}; |
| 126 | +
|
| 127 | +const formatCustomAmount = (): void => { |
| 128 | + if ( customAmount.value !== '' ) { |
| 129 | + customAmount.value = currencyFormatter.customAmountInput( numericAmount.value ); |
| 130 | + } |
| 131 | +}; |
| 132 | +
|
| 133 | +</script> |
0 commit comments