Skip to content

Commit

Permalink
fix: prevent inputs (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikhorn93 authored Jan 8, 2024
1 parent 9dd2279 commit 8330e43
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
10 changes: 9 additions & 1 deletion lib/mixins/SimpleProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ export default {
}
this.input(event.target.value)
},
beforeinput: evt => (!['number', 'integer'].includes(this.fullSchema.type) || !evt.data || /[\d,+-]/.test(evt.data)) || evt.preventDefault()
beforeinput: evt => {
if (['integer'].includes(this.fullSchema.type)) {
return !evt.data || /[\d+-]/.test(evt.data) || evt.preventDefault()
} else if (['number'].includes(this.fullSchema.type)) {
return !evt.data || /[\d,+-]/.test(evt.data) || evt.preventDefault()
} else {
return true
}
}
}
const scopedSlots = {}
let tooltipSlot = 'append-outer'
Expand Down
7 changes: 7 additions & 0 deletions lib/utils/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export const getRules = (schema, fullSchema, options, required, isOneOfSelect) =
const msg = options.messages.exclusiveMinimum.replace('{exclusiveMinimum}', fullSchema.exclusiveMinimum.toLocaleString(options.locale))
rules.push((val) => (val === undefined || val === null || val > fullSchema.exclusiveMinimum) || msg)
}
// custom number rule
if (['number', 'integer'].includes(fullSchema.type)) {
const msg = 'Der Wert muss eine Zahl sein.'
rules.push((val) => {
return (val === undefined || val === null || /[-+]?(\d+)(,\d*)?/.test(val)) || msg

This comment has been minimized.

Copy link
@darenegade

darenegade Jan 8, 2024

Member

[-+]?(\d+)(,\d+)?, oder

Sonst ist 1, valide

})
}
if (fullSchema.enum) {
rules.push((val) => (val === undefined || val === null || !!fullSchema.enum.find(item => deepEqual(item, val))) || '')
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@muenchen/vjsf",
"version": "2.21.8",
"version": "2.21.9",
"description": "Generate forms for the vuetify UI library (vuejs) based on annotated JSON schemas.",
"main": "dist/main.js",
"scripts": {
Expand Down

0 comments on commit 8330e43

Please sign in to comment.