diff --git a/src/components/common/VnInput.vue b/src/components/common/VnInput.vue
index 711e0d90a..5df3b7a11 100644
--- a/src/components/common/VnInput.vue
+++ b/src/components/common/VnInput.vue
@@ -25,6 +25,7 @@ const $props = defineProps({
});
const { t } = useI18n();
+const requiredFieldRule = (val) => !!val || t('globals.fieldRequired');
const vnInputRef = ref(null);
const value = computed({
get() {
@@ -53,7 +54,8 @@ defineExpose({
focus,
});
-const inputRules = [
+const mixinRules = [
+ requiredFieldRule,
(val) => {
const { min } = vnInputRef.value.$attrs;
if (min >= 0) if (Math.floor(val) < min) return t('inputMin', { value: min });
@@ -71,6 +73,7 @@ const inputRules = [
:class="{ required: $attrs.required }"
@keyup.enter="emit('keyup.enter')"
:clearable="false"
+ :rules="$attrs.required || $attrs.min ? mixinRules : null"
:lazy-rules="true"
hide-bottom-space
>
diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue
index 12d110170..1ee6930eb 100644
--- a/src/components/common/VnSelect.vue
+++ b/src/components/common/VnSelect.vue
@@ -1,10 +1,10 @@
@@ -173,6 +179,7 @@ watch(modelValue, (newValue) => {
fill-input
ref="vnSelectRef"
lazy-rules
+ :rules="mixinRules()"
:class="{ required: $attrs.required }"
virtual-scroll-slice-size="options.length"
>
diff --git a/src/composables/useValidator.js b/src/composables/useValidator.js
index 11e7188b3..a07f3e985 100644
--- a/src/composables/useValidator.js
+++ b/src/composables/useValidator.js
@@ -28,7 +28,7 @@ export function useValidator() {
}
const { t } = useI18n();
- const validations = function (validation) {
+ const validations = function (validation = {}) {
return {
format: (value) => {
const { allowNull, with: format, allowBlank } = validation;
@@ -71,12 +71,19 @@ export function useValidator() {
return validator.isInt(value) || 'Value should be integer';
return validator.isNumeric(value) || 'Value should be a number';
},
+ min: (value, min) => {
+ if (min >= 0)
+ if (Math.floor(value) < min) return t('inputMin', { value: min });
+ },
custom: (value) => validation.bindedFunction(value) || 'Invalid value',
};
};
+ // const requiredFieldRule = [(val) => validations({}).presence(val)];
return {
validate,
+ // requiredFieldRule,
+ validations,
models,
};
}