#6317 create vnCurrency #181
|
@ -1,33 +1,45 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useCapitalize } from 'src/composables/useCapitalize';
|
||||
import { useValidNumber } from 'src/composables/useValidNumber';
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import { useFirstUpper } from 'src/composables/useFirstUpper';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: { type: String, default: '' },
|
||||
currency: { type: String, default: 'euro' },
|
||||
icon: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const amount = ref();
|
||||
const emit = defineEmits(['update:modelValue']);
|
||||
|
||||
const isValidNumber = (value) => /^(\d|\d+(\.)?\d+)$/.test(value);
|
||||
const amount = computed({
|
||||
get() {
|
||||
return props.modelValue;
|
||||
},
|
||||
set(val) {
|
||||
emit('update:modelValue', val.replaceAll(',', '.'));
|
||||
jorgep marked this conversation as resolved
Outdated
alexm
commented
En angularjs fa aço: front/core/filters/currency.js ns si en vue hi ha algo paregut En angularjs fa aço: front/core/filters/currency.js ns si en vue hi ha algo paregut
jorgep
commented
Esto con el type number no es necesario. Esto con el type number no es necesario.
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<VnInput
|
||||
:label="useFirstUpper(t('amount'))"
|
||||
v-model="amount"
|
||||
jorgep marked this conversation as resolved
Outdated
alexm
commented
Html(i quasar) te la posibilitat de gastar type="number" En un component q soles accepta numeros (tambe dixa '.' i ',') seria lo mes apropiat Html(i quasar) te la posibilitat de gastar type="number"
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number
En un component q soles accepta numeros (tambe dixa '.' i ',') seria lo mes apropiat
jorgep
commented
Si gasto type="number" sale el banner predeterminado de html5 cuando escribes un número con coma, Una posible solución es añadir novalidate en el QForm. https://www.w3schools.com/tags/att_form_novalidate.asp Usando step="any" se admiten decimales con coma y punto. Si gasto type="number" sale el banner predeterminado de html5 cuando escribes un número con coma, Una posible solución es añadir novalidate en el QForm.
https://www.w3schools.com/tags/att_form_novalidate.asp
Usando step="any" se admiten decimales con coma y punto.
|
||||
:label="useCapitalize(t('amount'))"
|
||||
:rules="[(val) => useValidNumber(val) || !val]"
|
||||
is-outlined
|
||||
@update:model-value="
|
||||
(value) => {
|
||||
if (value.includes(',')) amount.value = amount.replace(',', '.');
|
||||
}
|
||||
"
|
||||
:rules="[(val) => isValidNumber(val) || !val || 'Please type a number']"
|
||||
lazy-rules
|
||||
>
|
||||
<template #prepend>
|
||||
<QIcon name="euro" size="sm" />
|
||||
<template #prepend v-if="icon">
|
||||
<QIcon :name="currency" size="sm" />
|
||||
</template>
|
||||
</VnInput>
|
||||
</template>
|
||||
<style lang="scss" scoped></style>
|
||||
<style lang="scss" scoped>
|
||||
.q-input {
|
||||
max-height: 44px;
|
||||
}
|
||||
</style>
|
||||
<i18n>
|
||||
es:
|
||||
amount: importe
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export function useValidNumber(value) {
|
||||
jorgep marked this conversation as resolved
Outdated
alexm
commented
Gastant type="number" ja te limita sols a numeros Gastant type="number" ja te limita sols a numeros
|
||||
return /^(\d|\d+(\.)?\d+)$/.test(value);
|
||||
}
|
||||
jorgep
commented
Se puede guardar como función propia de VnCurrency, pero igual puede hacer falta más adelante en otros sitios. Se puede guardar como función propia de VnCurrency, pero igual puede hacer falta más adelante en otros sitios.
|
|
@ -12,10 +12,6 @@ const props = defineProps({
|
|||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
function isValidNumber(value) {
|
||||
return /^(\d|\d+(\.|,)?\d+)$/.test(value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -158,7 +158,12 @@ async function insert() {
|
|||
</template>
|
||||
<template #body-cell-amount="{ row }">
|
||||
<QTd>
|
||||
<QInput v-model="row.amount" clearable clear-icon="close" />
|
||||
<QInput
|
||||
v-model="row.amount"
|
||||
type="number"
|
||||
jorgep marked this conversation as resolved
alexm
commented
Aci si que el has gastat Aci si que el has gastat
|
||||
clearable
|
||||
clear-icon="close"
|
||||
/>
|
||||
</QTd>
|
||||
</template>
|
||||
<template #body-cell-foreignvalue="{ row }">
|
||||
|
|
|
@ -8,6 +8,7 @@ import FetchData from 'components/FetchData.vue';
|
|||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import VnInputDate from 'components/common/VnInputDate.vue';
|
||||
import { useCapitalize } from 'src/composables/useCapitalize';
|
||||
import VnCurrency from 'src/components/common/VnCurrency.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
const props = defineProps({
|
||||
|
@ -137,16 +138,7 @@ const suppliersRef = ref();
|
|||
</QItem>
|
||||
<QItem>
|
||||
<QItemSection>
|
||||
<VnInput
|
||||
:label="t('Amount')"
|
||||
v-model="params.amount"
|
||||
is-outlined
|
||||
lazy-rules
|
||||
>
|
||||
<template #prepend>
|
||||
<QIcon name="euro" size="sm"></QIcon>
|
||||
</template>
|
||||
</VnInput>
|
||||
<VnCurrency v-model="params.amount" />
|
||||
</QItemSection>
|
||||
</QItem>
|
||||
<QItem class="q-mb-md">
|
||||
|
|
|
@ -6,6 +6,7 @@ import FetchData from 'components/FetchData.vue';
|
|||
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import VnInputDate from 'components/common/VnInputDate.vue';
|
||||
import VnCurrency from 'src/components/common/VnCurrency.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
const props = defineProps({
|
||||
|
@ -57,7 +58,12 @@ function setWorkers(data) {
|
|||
</QItem>
|
||||
<QItem>
|
||||
<QItemSection>
|
||||
<VnInput :label="t('Amount')" v-model="params.amount" is-outlined />
|
||||
<VnCurrency
|
||||
:label="t('Amount')"
|
||||
v-model="params.amount"
|
||||
is-outlined
|
||||
:icon="false"
|
||||
/>
|
||||
</QItemSection>
|
||||
</QItem>
|
||||
<QItem>
|
||||
|
|
|
@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n';
|
|||
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import VnInputDate from 'components/common/VnInputDate.vue';
|
||||
import VnCurrency from 'src/components/common/VnCurrency.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
const props = defineProps({
|
||||
|
@ -84,10 +85,10 @@ const props = defineProps({
|
|||
</QItem>
|
||||
<QItem>
|
||||
<QItemSection>
|
||||
<VnInput
|
||||
<VnCurrency
|
||||
v-model="params.amount"
|
||||
:label="t('invoiceOut.negativeBases.amount')"
|
||||
is-outlined
|
||||
:icon="false"
|
||||
/>
|
||||
</QItemSection>
|
||||
</QItem>
|
||||
|
|
Todo esto creo que se puede sustituir por const amount = defineModel()
Por lo que he visto en internet, hace falta Vue 3.4 pero tenemos vue 3.3.4