|
1 |
| -<html> |
2 |
| -<body> |
3 |
| - <form> |
4 |
| - <th:block th:fragment="input (label, name, type)"> |
5 |
| - <div th:with="valid=${!#fields.hasErrors(name)}" |
6 |
| - th:class="${'form-group' + (valid ? '' : ' has-error')}" |
7 |
| - class="form-group"> |
8 |
| - <label class="col-sm-2 control-label" th:text="${label}">Label</label> |
9 |
| - <div class="col-sm-10"> |
10 |
| - <div th:switch="${type}"> |
11 |
| - <input th:case="'text'" class="form-control" type="text" th:field="*{__${name}__}" /> |
12 |
| - <input th:case="'date'" class="form-control" type="date" th:field="*{__${name}__}"/> |
13 |
| - </div> |
14 |
| - <span th:if="${valid}" |
15 |
| - class="fa fa-ok form-control-feedback" |
16 |
| - aria-hidden="true"></span> |
17 |
| - <th:block th:if="${!valid}"> |
18 |
| - <span |
19 |
| - class="fa fa-remove form-control-feedback" |
20 |
| - aria-hidden="true"></span> |
21 |
| - <span class="help-inline" th:errors="*{__${name}__}">Error</span> |
22 |
| - </th:block> |
23 |
| - </div> |
| 1 | +<html xmlns:th="http://www.thymeleaf.org"> |
| 2 | +<!-- Define the fragment 'input' that takes label, name, and type as parameters --> |
| 3 | +<th:block th:fragment="input(label, name, type)"> |
| 4 | + <div th:with="valid=${!#fields.hasErrors(name)}" |
| 5 | + th:class="'form-group' + (valid ? '' : ' has-error')"> |
| 6 | + <label class="col-sm-2 control-label" th:text="${label}">Label</label> |
| 7 | + <div class="col-sm-10"> |
| 8 | + <div th:switch="${type}"> |
| 9 | + <!-- For text input --> |
| 10 | + <input th:case="'text'" class="form-control" type="text" th:field="*{__${name}__}" /> |
| 11 | + <!-- For date input --> |
| 12 | + <input th:case="'date'" class="form-control" type="date" th:field="*{__${name}__}" /> |
| 13 | + <!-- Add other input types as needed --> |
24 | 14 | </div>
|
25 |
| - </th:block> |
26 |
| - </form> |
27 |
| -</body> |
| 15 | + <!-- Show a check icon if there are no errors --> |
| 16 | + <span th:if="${valid}" class="fa fa-ok form-control-feedback" aria-hidden="true"></span> |
| 17 | + <!-- When there are errors, show an error icon and display error messages --> |
| 18 | + <th:block th:if="${!valid}"> |
| 19 | + <span class="fa fa-remove form-control-feedback" aria-hidden="true"></span> |
| 20 | + <span class="help-inline" th:errors="*{__${name}__}">Error</span> |
| 21 | + </th:block> |
| 22 | + </div> |
| 23 | + </div> |
| 24 | +</th:block> |
28 | 25 | </html>
|
0 commit comments