fix: comma input behavior

This commit is contained in:
puriphatt 2024-12-25 15:47:25 +07:00
parent 61501dba8d
commit 889d4afbf5
6 changed files with 113 additions and 50 deletions

View file

@ -1,7 +1,11 @@
<script setup lang="ts">
import { QSelect } from 'quasar';
import { onMounted, ref, watch, capitalize } from 'vue';
import { selectFilterOptionRefMod, commaInput } from 'stores/utils';
import {
selectFilterOptionRefMod,
commaInput,
formatNumberWithCommas,
} from 'stores/utils';
import { calculateAge, disabledAfterToday } from 'src/utils/datetime';
import useOptionStore from 'src/stores/options';
@ -236,9 +240,21 @@ watch(
:label="$t('customer.form.authorizedCapital')"
for="input-authorized-capital"
:model-value="authorizedCapital"
@blur="
() => {
let val = authorizedCapital.replace(/[^0-9.]/g, '');
if (!val.includes('.')) val = val + '.00';
val = formatNumberWithCommas(val);
authorizedCapital = val;
}
"
@update:model-value="
(v) => {
if (typeof v === 'string')
if (
isNaN(Number(typeof v === 'string' ? v.replace(/,/g, '') : v))
) {
authorizedCapital = '0';
} else if (typeof v === 'string')
authorizedCapital = commaInput(v, 'string');
}
"

View file

@ -1,5 +1,9 @@
<script setup lang="ts">
import { selectFilterOptionRefMod, commaInput } from 'stores/utils';
import {
selectFilterOptionRefMod,
commaInput,
formatNumberWithCommas,
} from 'stores/utils';
import { onMounted, watch } from 'vue';
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
@ -19,7 +23,6 @@ const wageRateText = defineModel<string>('wageRateText', { default: '0' });
const rate = ref<string>(commaInput(wageRate.value?.toString() || '0'));
const wageRate4Show = ref('');
const typeBusinessOption = ref([]);
const typeBusinessENOption = ref([]);
const jobPositionOption = ref([]);
@ -314,12 +317,19 @@ let jobPositionENFilter = selectFilterOptionRefMod(
class="col-md-3 col-6"
:label="$t('customer.form.payRate')"
:model-value="rate?.toString()"
@blur="
() => {
let val = rate.replace(/[^0-9.]/g, '');
if (!val.includes('.')) val = val + '.00';
val = formatNumberWithCommas(val);
rate = val;
}
"
@update:model-value="
(v) => {
if (typeof v === 'string') {
console.log(v);
rate = commaInput(v, 'string');
}
if (isNaN(Number(typeof v === 'string' ? v.replace(/,/g, '') : v))) {
rate = '0';
} else if (typeof v === 'string') rate = commaInput(v, 'string');
}
"
/>