Skip to content

Commit

Permalink
Merge pull request #447 from krooldonutz/separate-birthDate-and-birth…
Browse files Browse the repository at this point in the history
…Time

Added Separate Field In Form To Add Optional Birth Time (Issue #445)
  • Loading branch information
josdem authored Dec 6, 2024
2 parents 5036a3d + 2f23521 commit 27d87b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/josdem/vetlog/command/PetCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ public class PetCommand implements Command {
private transient List<PetImage> images = new ArrayList<>();

private transient List<Vaccination> vaccines = new ArrayList<>();

public void defaultBirthDateAndTime() {
this.birthDate = birthDate + "T" + "06:00";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public boolean supports(Class<?> clazz) {
@Override
public void validate(Object target, Errors errors) {
PetCommand petCommand = (PetCommand) target;
petCommand.defaultBirthDateAndTime();
validateBirthdate(errors, petCommand);
}

Expand Down
10 changes: 8 additions & 2 deletions src/main/resources/templates/pet/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<head th:insert="~{fragments/include}"/>
<script th:src="@{/assets/servizi-dog-theme/node_modules/jquery/dist/jquery.min.js}"></script>
<script th:src="@{/javascript/selector.js}"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
var today = new Date().toISOString().split('T')[0];
document.getElementById('birthDate').setAttribute('max', today);
});
</script>
</head>
<body class="login">
<div th:insert="~{fragments/header}"/>
Expand All @@ -29,7 +35,7 @@
<input type="file" name="image"/>
<br/>
<label for="birthDate"><h4 th:text="#{pet.birthDate}"/></label>
<input th:data-testid="birthDate" type="datetime-local" id="birthDate" name="birthDate">
<input th:data-testid="birthDate" type="date" id="birthDate" name="birthDate" min="${#dates.format(#dates.createNow(), 'yyyy-MM-dd')}">
<label th:if="${#fields.hasErrors('birthDate')}" th:errors="*{birthDate}"></label>
<br/>
<label for="dewormed"><h4 th:text="#{pet.dewormed}"/></label>
Expand Down Expand Up @@ -75,4 +81,4 @@
<br/><br/>
<div th:insert="~{fragments/footer}"/>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion src/main/resources/templates/pet/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<input type="file" name="image"/>
<br/>
<label for="birthDate"><h4 th:text="#{pet.birthDate}"/></label>
<input type="datetime-local" id="birthDate" name="birthDate" th:data-testid="petBirthdate" th:field="*{birthDate}">
<input th:data-testid="birthDate" type="date" id="birthDate" name="birthDate">
<label th:if="${#fields.hasErrors('birthDate')}" th:errors="*{birthDate}"></label>
<br/>
<label for="dewormed"><h4 th:text="#{pet.dewormed}"/></label>
Expand Down

0 comments on commit 27d87b6

Please sign in to comment.