#290 field name validation

This commit is contained in:
Michael Shanks 2020-07-02 21:09:49 +01:00
parent 4346bce4fd
commit 1da37b1fa5
1 changed files with 28 additions and 0 deletions

View File

@ -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() {
const errors = validate()
if (errors.length > 0) {
notifier.danger(
errors.join("/n")
)
return
}
await backendUiStore.actions.models.save({
model: $backendUiStore.draftModel,
})