#290 field name validation
This commit is contained in:
parent
4346bce4fd
commit
1da37b1fa5
|
@ -52,7 +52,35 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validate() {
|
||||||
|
let errors = []
|
||||||
|
for (let field of Object.values($backendUiStore.draftModel.schema)) {
|
||||||
|
const restrictedFieldNames = ["type", "modelId"]
|
||||||
|
if (field.name.startsWith("_")) {
|
||||||
|
errors.push(`field '${field.name}' - name cannot begin with '_''`)
|
||||||
|
} else if (restrictedFieldNames.includes(field.name)) {
|
||||||
|
errors.push(`field '${field.name}' - is a restricted name, please rename`)
|
||||||
|
} else if (!field.name || !field.name.trim()) {
|
||||||
|
errors.push("field name cannot be blank")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$backendUiStore.draftModel.name) {
|
||||||
|
errors.push("Table name cannot be blank")
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
async function saveModel() {
|
async function saveModel() {
|
||||||
|
const errors = validate()
|
||||||
|
if (errors.length > 0) {
|
||||||
|
notifier.danger(
|
||||||
|
errors.join("/n")
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await backendUiStore.actions.models.save({
|
await backendUiStore.actions.models.save({
|
||||||
model: $backendUiStore.draftModel,
|
model: $backendUiStore.draftModel,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue