Skip to content

Commit

Permalink
refactor(Price add): avoid raising validation error for optional fiel…
Browse files Browse the repository at this point in the history
…ds. More compact display for receipt-only fields. ref #974
  • Loading branch information
raphodn committed Dec 14, 2024
1 parent 84eab3e commit ca865b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/components/PriceInputRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
:label="$t('Common.QuantityBought')"
type="text"
inputmode="numeric"
:rules="receiptQuantityRules"
:prepend-inner-icon="PROOF_TYPE_RECEIPT_ICON"
hide-details="auto"
/>
Expand Down Expand Up @@ -112,6 +113,13 @@ export default {
value => !value.match(/\.\d{3}/) || this.$t('PriceRules.TwoDecimals'),
]
},
receiptQuantityRules() {
if (!this.priceForm.receipt_quantity) return [() => true] // optional field
return [
value => !isNaN(value) || this.$t('PriceRules.Number'),
value => Number(value) >= 1 || this.$t('PriceRules.Positive'),
]
},
priceFormFilled() {
let keys = ['price', 'currency']
return Object.keys(this.priceForm).filter(k => keys.includes(k)).every(k => !!this.priceForm[k])
Expand Down
26 changes: 15 additions & 11 deletions src/components/ProofMetadataInputRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,27 @@
</v-col>
</v-row>
<v-row v-if="proofIsTypeReceipt">
<v-col class="pb-0" cols="12">
<h3 class="mb-1">
<v-icon size="x-small" :icon="PROOF_TYPE_RECEIPT_ICON" />
{{ $t('Common.AdditionalInfo') }}
</h3>
</v-col>
</v-row>
<v-row v-if="proofIsTypeReceipt" class="mt-0">
<v-col cols="6">
<v-text-field
v-model="proofMetadataForm.receipt_price_count"
density="compact"
:label="$t('Common.ReceiptPriceCount')"
type="text"
inputmode="numeric"
:rules="priceCountRules"
:prepend-inner-icon="PROOF_TYPE_RECEIPT_ICON"
hide-details="auto"
/>
</v-col>
<v-col cols="6">
<v-text-field
v-model="proofMetadataForm.receipt_price_total"
density="compact"
:label="$t('Common.ReceiptPriceTotal')"
type="text"
inputmode="decimal"
:rules="priceRules"
:rules="priceTotalRules"
:prepend-inner-icon="PROOF_TYPE_RECEIPT_ICON"
:suffix="proofMetadataForm.currency"
hide-details="auto"
@update:modelValue="newValue => proofMetadataForm.receipt_price_total = fixComma(newValue)"
Expand Down Expand Up @@ -103,9 +100,16 @@ export default {
proofIsTypeReceipt() {
return this.proofType === constants.PROOF_TYPE_RECEIPT
},
priceRules() {
priceCountRules() {
if (!this.proofMetadataForm.receipt_price_count) return [() => true] // optional field
return [
value => !isNaN(value) || this.$t('PriceRules.Number'),
value => Number(value) >= 1 || this.$t('PriceRules.Positive'),
]
},
priceTotalRules() {
if (!this.proofMetadataForm.receipt_price_total) return [() => true] // optional field
return [
// value => !!value && !!value.trim() || this.$t('PriceRules.AmountRequired'),
value => !!value && !value.trim().match(/ /) || this.$t('PriceRules.NoSpaces'),
value => !isNaN(value) || this.$t('PriceRules.Number'),
value => Number(value) >= 0 || this.$t('PriceRules.Positive'),
Expand Down

0 comments on commit ca865b1

Please sign in to comment.