mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-08 13:28:21 +00:00
Refactor DbField
to handle disableEditField
explicitly.
Removed the `isDisable` parameter from the `DbField` constructor and set `disableEditField` through a dedicated method. Updated relevant logic to ensure proper handling of non-editable fields across the application.
This commit is contained in:
parent
28063ed583
commit
50f2844319
@ -356,7 +356,7 @@ public class SnapAdmin {
|
||||
DisplayFormat displayFormat = f.getAnnotation(DisplayFormat.class);
|
||||
DisableEditField disableEdit = f.getAnnotation(DisableEditField.class);
|
||||
|
||||
DbField field = new DbField(f.getName(), fieldName, f, fieldType, schema, displayFormat != null ? displayFormat.format() : null, disableEdit != null);
|
||||
DbField field = new DbField(f.getName(), fieldName, f, fieldType, schema, displayFormat != null ? displayFormat.format() : null);
|
||||
field.setConnectedType(connectedType);
|
||||
|
||||
Id[] idAnnotations = f.getAnnotationsByType(Id.class);
|
||||
@ -367,6 +367,8 @@ public class SnapAdmin {
|
||||
if (field.isPrimaryKey())
|
||||
field.setNullable(false);
|
||||
|
||||
field.setDisableEditField(disableEdit != null);
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
|
@ -96,14 +96,13 @@ public class DbField {
|
||||
@JsonIgnore
|
||||
private DbObjectSchema schema;
|
||||
|
||||
public DbField(String javaName, String name, Field field, DbFieldType type, DbObjectSchema schema, String format, boolean isDisable) {
|
||||
public DbField(String javaName, String name, Field field, DbFieldType type, DbObjectSchema schema, String format) {
|
||||
this.javaName = javaName;
|
||||
this.dbName = name;
|
||||
this.schema = schema;
|
||||
this.field = field;
|
||||
this.type = type;
|
||||
this.format = format;
|
||||
this.disableEditField = isDisable;
|
||||
}
|
||||
|
||||
public String getJavaName() {
|
||||
|
@ -31,7 +31,7 @@
|
||||
<form class="form" enctype="multipart/form-data" method="post" th:action="|/${snapadmin_baseUrl}/model/${className}/create|">
|
||||
<input type="hidden" name="__snapadmin_create" th:value="${create}">
|
||||
<div th:each="field : ${schema.getSortedFields(false)}" class="mt-2"
|
||||
th:unless="${(field.isGeneratedValue() && create) || field.isDisableEditField()}"
|
||||
th:unless="${field.isGeneratedValue() && create || field.isDisableEditField()}"
|
||||
th:classAppend="|${validationErrors != null && validationErrors.hasErrors(field.getJavaName()) ? 'invalid' : ''}|">
|
||||
<label th:for="|__id_${field.getName()}|" class="mb-1 fw-bold">
|
||||
<span th:if="${!field.isNullable() && !field.isPrimaryKey()}">
|
||||
|
Loading…
x
Reference in New Issue
Block a user