Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix-front into 6818-saySimpleIntegration

This commit is contained in:
Jorge Penadés 2024-11-08 17:49:35 +01:00
commit 462382ecb5
7 changed files with 49 additions and 30 deletions

View File

@ -1,8 +1,11 @@
<script setup> <script setup>
import { computed, ref } from 'vue'; import { computed, ref, useAttrs } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useValidator } from 'src/composables/useValidator'; import { useRequired } from 'src/composables/useRequired';
const $attrs = useAttrs();
const { isRequired, requiredFieldRule } = useRequired($attrs);
const { t } = useI18n();
const emit = defineEmits([ const emit = defineEmits([
'update:modelValue', 'update:modelValue',
'update:options', 'update:options',
@ -32,10 +35,6 @@ const $props = defineProps({
default: true, default: true,
}, },
}); });
const { validations } = useValidator();
const { t } = useI18n();
const requiredFieldRule = (val) => validations().required($attrs.required, val);
const vnInputRef = ref(null); const vnInputRef = ref(null);
const value = computed({ const value = computed({
@ -65,8 +64,6 @@ const focus = () => {
defineExpose({ defineExpose({
focus, focus,
}); });
import { useAttrs } from 'vue';
const $attrs = useAttrs();
const mixinRules = [ const mixinRules = [
requiredFieldRule, requiredFieldRule,
@ -90,7 +87,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"

View File

@ -4,8 +4,13 @@ import { date } from 'quasar';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useAttrs } from 'vue'; import { useAttrs } from 'vue';
import VnDate from './VnDate.vue'; import VnDate from './VnDate.vue';
import { useRequired } from 'src/composables/useRequired';
const $attrs = useAttrs();
const { isRequired, requiredFieldRule } = useRequired($attrs);
const model = defineModel({ type: [String, Date] }); const model = defineModel({ type: [String, Date] });
const { t } = useI18n();
const $props = defineProps({ const $props = defineProps({
isOutlined: { isOutlined: {
type: Boolean, type: Boolean,
@ -16,18 +21,13 @@ const $props = defineProps({
default: true, default: true,
}, },
}); });
import { useValidator } from 'src/composables/useValidator';
const { validations } = useValidator();
const { t } = useI18n();
const requiredFieldRule = (val) => validations().required($attrs.required, 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 +104,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"

View File

@ -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>

View File

@ -2,11 +2,12 @@
import { computed, ref, useAttrs } from 'vue'; import { computed, ref, useAttrs } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { date } from 'quasar'; import { date } from 'quasar';
import { useValidator } from 'src/composables/useValidator';
import VnTime from './VnTime.vue'; import VnTime from './VnTime.vue';
import { useRequired } from 'src/composables/useRequired';
const { validations } = useValidator();
const $attrs = useAttrs(); const $attrs = useAttrs();
const { isRequired, requiredFieldRule } = useRequired($attrs);
const { t } = useI18n();
const model = defineModel({ type: String }); const model = defineModel({ type: String });
const props = defineProps({ const props = defineProps({
timeOnly: { timeOnly: {
@ -20,8 +21,6 @@ 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 requiredFieldRule = (val) => validations().required($attrs.required, 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 +77,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"

View File

@ -3,9 +3,12 @@ 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 { ref } from 'vue';
import { useAttrs } from 'vue';
import { useRequired } from 'src/composables/useRequired';
const { t } = useI18n(); const { t } = useI18n();
const emit = defineEmits(['update:model-value', 'update:options']); const emit = defineEmits(['update:model-value', 'update:options']);
const $attrs = useAttrs();
const { isRequired, requiredFieldRule } = useRequired($attrs);
const props = defineProps({ const props = defineProps({
location: { location: {
type: Object, type: Object,
@ -13,6 +16,7 @@ const props = defineProps({
}, },
}); });
const mixinRules = [requiredFieldRule];
const locationProperties = [ const locationProperties = [
'postcode', 'postcode',
(obj) => (obj) =>
@ -69,11 +73,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

View File

@ -2,9 +2,11 @@
import { ref, toRefs, computed, watch, onMounted, useAttrs } from 'vue'; import { ref, toRefs, computed, watch, onMounted, useAttrs } from 'vue';
import { useI18n } from 'vue-i18n'; 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 { useRequired } from 'src/composables/useRequired';
const emit = defineEmits(['update:modelValue', 'update:options', 'remove']); const emit = defineEmits(['update:modelValue', 'update:options', 'remove']);
const $attrs = useAttrs();
const { t } = useI18n();
const { isRequired, requiredFieldRule } = useRequired($attrs);
const $props = defineProps({ const $props = defineProps({
modelValue: { modelValue: {
type: [String, Number, Object], type: [String, Number, Object],
@ -87,10 +89,7 @@ const $props = defineProps({
default: false, default: false,
}, },
}); });
const { validations } = useValidator();
const requiredFieldRule = (val) => validations().required($attrs.required, val);
const $attrs = useAttrs();
const { t } = useI18n();
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 +256,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

View File

@ -0,0 +1,13 @@
import { useValidator } from 'src/composables/useValidator';
export function useRequired($attrs) {
const { validations } = useValidator();
const isRequired = Object.keys($attrs).includes('required');
const requiredFieldRule = (val) => validations().required(isRequired, val);
return {
isRequired,
requiredFieldRule,
};
}