mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-09 05:48:20 +00:00
Highlighting inputs with errors
This commit is contained in:
parent
13b45e62b8
commit
c17d80514a
@ -439,24 +439,13 @@ public class DefaultDbAdminController {
|
|||||||
pkValue = null;
|
pkValue = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkValue == null) {
|
|
||||||
try {
|
try {
|
||||||
|
if (pkValue == null) {
|
||||||
Object newPrimaryKey = repository.create(schema, params, files, pkValue);
|
Object newPrimaryKey = repository.create(schema, params, files, pkValue);
|
||||||
repository.attachManyToMany(schema, newPrimaryKey, multiValuedParams);
|
repository.attachManyToMany(schema, newPrimaryKey, multiValuedParams);
|
||||||
pkValue = newPrimaryKey.toString();
|
pkValue = newPrimaryKey.toString();
|
||||||
attr.addFlashAttribute("message", "Item created successfully.");
|
attr.addFlashAttribute("message", "Item created successfully.");
|
||||||
saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE", schema.getClassName()));
|
saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE", schema.getClassName()));
|
||||||
} catch (DataIntegrityViolationException | UncategorizedSQLException | IdentifierGenerationException e) {
|
|
||||||
attr.addFlashAttribute("errorTitle", "Unable to INSERT row");
|
|
||||||
attr.addFlashAttribute("error", e.getMessage());
|
|
||||||
attr.addFlashAttribute("params", params);
|
|
||||||
} catch (ConstraintViolationException e) {
|
|
||||||
attr.addFlashAttribute("errorTitle", "Unable to INSERT row (validation error)");
|
|
||||||
attr.addFlashAttribute("error", "See below for details");
|
|
||||||
attr.addFlashAttribute("validationErrors", new ValidationErrorsContainer(e));
|
|
||||||
attr.addFlashAttribute("params", params);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Optional<DbObject> object = repository.findById(schema, pkValue);
|
Optional<DbObject> object = repository.findById(schema, pkValue);
|
||||||
|
|
||||||
@ -466,40 +455,29 @@ public class DefaultDbAdminController {
|
|||||||
attr.addFlashAttribute("error", "Item with id " + object.get().getPrimaryKeyValue() + " already exists.");
|
attr.addFlashAttribute("error", "Item with id " + object.get().getPrimaryKeyValue() + " already exists.");
|
||||||
attr.addFlashAttribute("params", params);
|
attr.addFlashAttribute("params", params);
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
repository.update(schema, params, files);
|
repository.update(schema, params, files);
|
||||||
repository.attachManyToMany(schema, pkValue, multiValuedParams);
|
repository.attachManyToMany(schema, pkValue, multiValuedParams);
|
||||||
attr.addFlashAttribute("message", "Item saved successfully.");
|
attr.addFlashAttribute("message", "Item saved successfully.");
|
||||||
saveAction(new UserAction(schema.getTableName(), pkValue, "EDIT", schema.getClassName()));
|
saveAction(new UserAction(schema.getTableName(), pkValue, "EDIT", schema.getClassName()));
|
||||||
} catch (DataIntegrityViolationException | UncategorizedSQLException | IdentifierGenerationException e) {
|
|
||||||
attr.addFlashAttribute("errorTitle", "Unable to UPDATE row (no changes applied)");
|
|
||||||
attr.addFlashAttribute("error", e.getMessage());
|
|
||||||
attr.addFlashAttribute("params", params);
|
|
||||||
} catch (ConstraintViolationException e) {
|
|
||||||
attr.addFlashAttribute("errorTitle", "Unable to INSERT row (validation error)");
|
|
||||||
attr.addFlashAttribute("error", "See below for details");
|
|
||||||
attr.addFlashAttribute("validationErrors", new ValidationErrorsContainer(e));
|
|
||||||
attr.addFlashAttribute("params", params);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
Object newPrimaryKey = repository.create(schema, params, files, pkValue);
|
Object newPrimaryKey = repository.create(schema, params, files, pkValue);
|
||||||
repository.attachManyToMany(schema, newPrimaryKey, multiValuedParams);
|
repository.attachManyToMany(schema, newPrimaryKey, multiValuedParams);
|
||||||
attr.addFlashAttribute("message", "Item created successfully");
|
attr.addFlashAttribute("message", "Item created successfully");
|
||||||
saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE", schema.getClassName()));
|
saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE", schema.getClassName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (DataIntegrityViolationException | UncategorizedSQLException | IdentifierGenerationException e) {
|
} catch (DataIntegrityViolationException | UncategorizedSQLException | IdentifierGenerationException e) {
|
||||||
attr.addFlashAttribute("errorTitle", "Unable to INSERT row (no changes applied)");
|
attr.addFlashAttribute("errorTitle", "Error");
|
||||||
attr.addFlashAttribute("error", e.getMessage());
|
attr.addFlashAttribute("error", e.getMessage());
|
||||||
attr.addFlashAttribute("params", params);
|
attr.addFlashAttribute("params", params);
|
||||||
} catch (ConstraintViolationException e) {
|
} catch (ConstraintViolationException e) {
|
||||||
attr.addFlashAttribute("errorTitle", "Unable to INSERT row (validation error)");
|
attr.addFlashAttribute("errorTitle", "Validation error");
|
||||||
attr.addFlashAttribute("error", "See below for details");
|
attr.addFlashAttribute("error", "See below for details");
|
||||||
attr.addFlashAttribute("validationErrors", new ValidationErrorsContainer(e));
|
attr.addFlashAttribute("validationErrors", new ValidationErrorsContainer(e));
|
||||||
attr.addFlashAttribute("params", params);
|
attr.addFlashAttribute("params", params);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attr.getFlashAttributes().containsKey("error")) {
|
if (attr.getFlashAttributes().containsKey("error")) {
|
||||||
if (create)
|
if (create)
|
||||||
|
@ -22,6 +22,10 @@ public class ValidationErrorsContainer {
|
|||||||
return errors.getOrDefault(name, new ArrayList<>());
|
return errors.getOrDefault(name, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasErrors(String name) {
|
||||||
|
return forField(name).size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return errors.isEmpty();
|
return errors.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.invalid input {
|
||||||
|
border-color: red !important;
|
||||||
|
}
|
||||||
|
|
||||||
.separator-light {
|
.separator-light {
|
||||||
opacity: 25%;
|
opacity: 25%;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
th:value="${value}"
|
th:value="${value}"
|
||||||
th:name="${name}"
|
th:name="${name}"
|
||||||
class="form-control " th:id="|__id_${field.getName()}|"
|
class="form-control" th:id="|__id_${field.getName()}|"
|
||||||
th:classAppend="|${(field.isPrimaryKey() && object != null) ||
|
th:classAppend="|${(field.isPrimaryKey() && object != null) ||
|
||||||
(field.isReadOnly() && !create) ? 'disable' : ''}|"
|
(field.isReadOnly() && !create) ? 'disable' : ''}|"
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@
|
|||||||
<h3 class="fw-bold mb-4" th:text="${create ? schema.getJavaClass().getSimpleName() : object.getDisplayName()}"></h3>
|
<h3 class="fw-bold mb-4" th:text="${create ? schema.getJavaClass().getSimpleName() : object.getDisplayName()}"></h3>
|
||||||
<form class="form" enctype="multipart/form-data" method="post" th:action="|/${dbadmin_baseUrl}/model/${className}/create|">
|
<form class="form" enctype="multipart/form-data" method="post" th:action="|/${dbadmin_baseUrl}/model/${className}/create|">
|
||||||
<input type="hidden" name="__dbadmin_create" th:value="${create}">
|
<input type="hidden" name="__dbadmin_create" th:value="${create}">
|
||||||
<div th:each="field : ${schema.getSortedFields(false)}" class="mt-2">
|
<div th:each="field : ${schema.getSortedFields(false)}" class="mt-2"
|
||||||
|
th:classAppend="|${validationErrors != null && validationErrors.hasErrors(field.getJavaName()) ? 'invalid' : ''}|">
|
||||||
<label th:for="|__id_${field.getName()}|" class="mb-1 fw-bold">
|
<label th:for="|__id_${field.getName()}|" class="mb-1 fw-bold">
|
||||||
<span th:if="${!field.isNullable() && !field.isPrimaryKey()}">
|
<span th:if="${!field.isNullable() && !field.isPrimaryKey()}">
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user