This commit is contained in:
einhornimmond 2025-02-04 13:02:10 +01:00
parent 52414789cd
commit 851db7e8c5
3 changed files with 16 additions and 22 deletions

View File

@ -119,13 +119,13 @@ const {
hours: props.modelValue.hours,
amount: props.modelValue.amount,
},
validationSchema
validationSchema,
})
const { meta: dataFieldMeta } = useField('date')
const updateField = (newValue, name) => {
if(typeof name === 'string' && name.length) {
if (typeof name === 'string' && name.length) {
setFieldValue(name, newValue)
}
}
@ -173,7 +173,7 @@ watch(
() => formValues.hours,
() => {
updateAmount(formValues.hours)
}
},
)
function updateAmount(hours) {

View File

@ -19,10 +19,10 @@
</template>
<script setup>
import { computed } from 'vue'
import { computed, defineOptions } from 'vue'
defineOptions({
inheritAttrs: false
inheritAttrs: false,
})
const props = defineProps({
@ -38,26 +38,21 @@ const props = defineProps({
type: String,
required: true,
},
name: {
type: String,
required: true,
},
name: [String, Number],
schemaDescription: {
type: Object,
required: true,
},
})
const emit = defineEmits()
const emit = defineEmits('update:modelValue')
const updateValue = (newValue) => emit('update:modelValue', newValue, props.name)
// extract additional parameter like min and max from schema
const getDateOnly = (rules, name) => rules.find(test => test.name === name)?.params[name]
const rules = props.schemaDescription.tests
const minValue = getDateOnly(rules, 'min')
const maxValue = getDateOnly(rules, 'max')
const getDateOnly = (rules, name) => rules.find((test) => test.name === name)?.params[name]
const minValue = computed(() => getDateOnly(props.schemaDescription.tests, 'min'))
const maxValue = computed(() => getDateOnly(props.schemaDescription.tests, 'max'))
const wrapperClassName = computed(() => `input-${props.name}`)
const labelFor = computed(() => `${props.name}-input-field`)
</script>
</script>

View File

@ -1,15 +1,14 @@
import {object, string, date } from 'yup'
import { object, string, date } from 'yup'
export const createContributionFormValidation = (t) => {
return object({
// The date field is required and needs to be a valid date
// contribution date
date:
date()
date: date()
.required(t('contribution.noDateSelected'))
.min((new Date(new Date().setMonth(new Date().getMonth() - 1, 1))).toISOString().slice(0,10)) // min date is first day of last month
.max(new Date().toISOString().slice(0,10))
.min(new Date(new Date().setMonth(new Date().getMonth() - 1, 1)).toISOString().slice(0, 10)) // min date is first day of last month
.max(new Date().toISOString().slice(0, 10))
.default(''), // date cannot be in the future
memo: string().required(t('')).min(5).max(255)
memo: string().required(t('')).min(5).max(255),
})
}