perf: use required instead :required="true"
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
458c6b0f42
commit
4b00ab877c
|
@ -2,6 +2,7 @@
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useValidator } from 'src/composables/useValidator';
|
import { useValidator } from 'src/composables/useValidator';
|
||||||
|
import { useAttrs } from 'vue';
|
||||||
|
|
||||||
const emit = defineEmits([
|
const emit = defineEmits([
|
||||||
'update:modelValue',
|
'update:modelValue',
|
||||||
|
@ -29,10 +30,11 @@ const $props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { validations } = useValidator();
|
const { validations } = useValidator();
|
||||||
|
const $attrs = useAttrs();
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const requiredFieldRule = (val) => validations().required($attrs.required, val);
|
const isRequired = computed(() => Object.keys($attrs).includes('required'));
|
||||||
|
const requiredFieldRule = (val) => validations().required(isRequired.value, val);
|
||||||
const vnInputRef = ref(null);
|
const vnInputRef = ref(null);
|
||||||
const value = computed({
|
const value = computed({
|
||||||
get() {
|
get() {
|
||||||
|
@ -60,8 +62,6 @@ const focus = () => {
|
||||||
defineExpose({
|
defineExpose({
|
||||||
focus,
|
focus,
|
||||||
});
|
});
|
||||||
import { useAttrs } from 'vue';
|
|
||||||
const $attrs = useAttrs();
|
|
||||||
|
|
||||||
const mixinRules = [
|
const mixinRules = [
|
||||||
requiredFieldRule,
|
requiredFieldRule,
|
||||||
|
@ -85,7 +85,7 @@ const mixinRules = [
|
||||||
v-model="value"
|
v-model="value"
|
||||||
v-bind="{ ...$attrs, ...styleAttrs }"
|
v-bind="{ ...$attrs, ...styleAttrs }"
|
||||||
:type="$attrs.type"
|
:type="$attrs.type"
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: isRequired }"
|
||||||
@keyup.enter="emit('keyup.enter')"
|
@keyup.enter="emit('keyup.enter')"
|
||||||
:clearable="false"
|
:clearable="false"
|
||||||
:rules="mixinRules"
|
:rules="mixinRules"
|
||||||
|
|
|
@ -6,6 +6,8 @@ import { useAttrs } from 'vue';
|
||||||
import VnDate from './VnDate.vue';
|
import VnDate from './VnDate.vue';
|
||||||
|
|
||||||
const model = defineModel({ type: [String, Date] });
|
const model = defineModel({ type: [String, Date] });
|
||||||
|
const $attrs = useAttrs();
|
||||||
|
const { t } = useI18n();
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
isOutlined: {
|
isOutlined: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
@ -19,15 +21,14 @@ const $props = defineProps({
|
||||||
import { useValidator } from 'src/composables/useValidator';
|
import { useValidator } from 'src/composables/useValidator';
|
||||||
const { validations } = useValidator();
|
const { validations } = useValidator();
|
||||||
|
|
||||||
const { t } = useI18n();
|
const isRequired = computed(() => Object.keys($attrs).includes('required'));
|
||||||
const requiredFieldRule = (val) => validations().required($attrs.required, val);
|
const requiredFieldRule = (val) => validations().required(isRequired.value, val);
|
||||||
const vnInputDateRef = ref(null);
|
const vnInputDateRef = ref(null);
|
||||||
|
|
||||||
const dateFormat = 'DD/MM/YYYY';
|
const dateFormat = 'DD/MM/YYYY';
|
||||||
const isPopupOpen = ref();
|
const isPopupOpen = ref();
|
||||||
const hover = ref();
|
const hover = ref();
|
||||||
const mask = ref();
|
const mask = ref();
|
||||||
const $attrs = useAttrs();
|
|
||||||
|
|
||||||
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
|
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ const manageDate = (date) => {
|
||||||
:mask="mask"
|
:mask="mask"
|
||||||
placeholder="dd/mm/aaaa"
|
placeholder="dd/mm/aaaa"
|
||||||
v-bind="{ ...$attrs, ...styleAttrs }"
|
v-bind="{ ...$attrs, ...styleAttrs }"
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: isRequired }"
|
||||||
:rules="mixinRules"
|
:rules="mixinRules"
|
||||||
:clearable="false"
|
:clearable="false"
|
||||||
@click="isPopupOpen = true"
|
@click="isPopupOpen = true"
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { useAttrs } from 'vue';
|
||||||
|
|
||||||
const model = defineModel({ type: [Number, String] });
|
const model = defineModel({ type: [Number, String] });
|
||||||
|
const $attrs = useAttrs();
|
||||||
|
const step = ref($attrs.step || 0.01);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VnInput v-bind="$attrs" v-model.number="model" type="number" />
|
<VnInput v-bind="$attrs" v-model.number="model" type="number" :step="step" />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { useValidator } from 'src/composables/useValidator';
|
||||||
import VnTime from './VnTime.vue';
|
import VnTime from './VnTime.vue';
|
||||||
|
|
||||||
const { validations } = useValidator();
|
const { validations } = useValidator();
|
||||||
|
const { t } = useI18n();
|
||||||
const $attrs = useAttrs();
|
const $attrs = useAttrs();
|
||||||
const model = defineModel({ type: String });
|
const model = defineModel({ type: String });
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
@ -20,8 +21,8 @@ const props = defineProps({
|
||||||
});
|
});
|
||||||
const vnInputTimeRef = ref(null);
|
const vnInputTimeRef = ref(null);
|
||||||
const initialDate = ref(model.value ?? Date.vnNew());
|
const initialDate = ref(model.value ?? Date.vnNew());
|
||||||
const { t } = useI18n();
|
const isRequired = computed(() => Object.keys($attrs).includes('required'));
|
||||||
const requiredFieldRule = (val) => validations().required($attrs.required, val);
|
const requiredFieldRule = (val) => validations().required(isRequired.value, val);
|
||||||
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
|
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
|
||||||
const dateFormat = 'HH:mm';
|
const dateFormat = 'HH:mm';
|
||||||
const isPopupOpen = ref();
|
const isPopupOpen = ref();
|
||||||
|
@ -78,7 +79,7 @@ function dateToTime(newDate) {
|
||||||
placeholder="--:--"
|
placeholder="--:--"
|
||||||
v-model="formattedTime"
|
v-model="formattedTime"
|
||||||
v-bind="{ ...$attrs, ...styleAttrs }"
|
v-bind="{ ...$attrs, ...styleAttrs }"
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: isRequired }"
|
||||||
style="min-width: 100px"
|
style="min-width: 100px"
|
||||||
:rules="mixinRules"
|
:rules="mixinRules"
|
||||||
@click="isPopupOpen = false"
|
@click="isPopupOpen = false"
|
||||||
|
|
|
@ -2,10 +2,14 @@
|
||||||
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
|
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
|
||||||
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const emit = defineEmits(['update:model-value', 'update:options']);
|
const emit = defineEmits(['update:model-value', 'update:options']);
|
||||||
|
const { validations } = useValidator();
|
||||||
|
|
||||||
|
import { useAttrs } from 'vue';
|
||||||
|
import { useValidator } from 'src/composables/useValidator';
|
||||||
|
const $attrs = useAttrs();
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
location: {
|
location: {
|
||||||
type: Object,
|
type: Object,
|
||||||
|
@ -13,6 +17,10 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isRequired = computed(() => Object.keys($attrs).includes('required'));
|
||||||
|
const requiredFieldRule = (val) => validations().required(isRequired.value, val);
|
||||||
|
|
||||||
|
const mixinRules = [requiredFieldRule];
|
||||||
const locationProperties = [
|
const locationProperties = [
|
||||||
'postcode',
|
'postcode',
|
||||||
(obj) =>
|
(obj) =>
|
||||||
|
@ -69,11 +77,13 @@ const handleModelValue = (data) => {
|
||||||
:label="t('Location')"
|
:label="t('Location')"
|
||||||
:placeholder="t('search_by_postalcode')"
|
:placeholder="t('search_by_postalcode')"
|
||||||
:input-debounce="300"
|
:input-debounce="300"
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: isRequired }"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
clearable
|
clearable
|
||||||
:emit-value="false"
|
:emit-value="false"
|
||||||
:tooltip="t('Create new location')"
|
:tooltip="t('Create new location')"
|
||||||
|
:rules="mixinRules"
|
||||||
|
:lazy-rules="true"
|
||||||
>
|
>
|
||||||
<template #form>
|
<template #form>
|
||||||
<CreateNewPostcode
|
<CreateNewPostcode
|
||||||
|
|
|
@ -4,7 +4,8 @@ import { useI18n } from 'vue-i18n';
|
||||||
import FetchData from 'src/components/FetchData.vue';
|
import FetchData from 'src/components/FetchData.vue';
|
||||||
import { useValidator } from 'src/composables/useValidator';
|
import { useValidator } from 'src/composables/useValidator';
|
||||||
const emit = defineEmits(['update:modelValue', 'update:options', 'remove']);
|
const emit = defineEmits(['update:modelValue', 'update:options', 'remove']);
|
||||||
|
const $attrs = useAttrs();
|
||||||
|
const { t } = useI18n();
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: [String, Number, Object],
|
type: [String, Number, Object],
|
||||||
|
@ -88,9 +89,9 @@ const $props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { validations } = useValidator();
|
const { validations } = useValidator();
|
||||||
const requiredFieldRule = (val) => validations().required($attrs.required, val);
|
|
||||||
const $attrs = useAttrs();
|
const isRequired = computed(() => Object.keys($attrs).includes('required'));
|
||||||
const { t } = useI18n();
|
const requiredFieldRule = (val) => validations().required(isRequired.value, val);
|
||||||
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
|
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
|
||||||
const { optionLabel, optionValue, optionFilter, optionFilterValue, options, modelValue } =
|
const { optionLabel, optionValue, optionFilter, optionFilterValue, options, modelValue } =
|
||||||
toRefs($props);
|
toRefs($props);
|
||||||
|
@ -257,7 +258,7 @@ defineExpose({ opts: myOptions });
|
||||||
:fill-input="nullishToTrue($attrs['fill-input'])"
|
:fill-input="nullishToTrue($attrs['fill-input'])"
|
||||||
ref="vnSelectRef"
|
ref="vnSelectRef"
|
||||||
lazy-rules
|
lazy-rules
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: isRequired }"
|
||||||
:rules="mixinRules"
|
:rules="mixinRules"
|
||||||
virtual-scroll-slice-size="options.length"
|
virtual-scroll-slice-size="options.length"
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
|
|
Loading…
Reference in New Issue