Skip to content

Commit c300e93

Browse files
committed
add catalog price form: render field errors
1 parent f0192cd commit c300e93

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/main/java/ru/mystamps/web/feature/series/HtmxSeriesController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public String addCatalogPrice(
143143
@Valid AddCatalogPriceForm form,
144144
BindingResult result,
145145
@AuthenticationPrincipal CustomUserDetails currentUser,
146+
Model model,
146147
HttpServletResponse response
147148
) throws IOException {
148149

@@ -158,8 +159,9 @@ public String addCatalogPrice(
158159

159160
if (result.hasErrors()) {
160161
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
161-
// XXX: implement
162-
return null;
162+
model.addAttribute("isHtmx", true);
163+
model.addAttribute("seriesId", seriesId);
164+
return "series/info :: AddCatalogPriceForm";
163165
}
164166

165167
Integer currentUserId = currentUser.getUserId();

src/main/webapp/WEB-INF/views/series/info.html

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,17 +410,19 @@ <h5 th:text="#{t_hidden_images}">Hidden images</h5>
410410
<div id="add-release-year" sec:authorize="hasAuthority('CREATE_SERIES')" th:if="${series.releaseYear == null}"></div>
411411

412412
<div id="add-catalog-price" sec:authorize="hasAuthority('CREATE_SERIES')">
413-
<div class="col-sm-12 form-group">
413+
<div class="col-sm-12 form-group" th:fragment="AddCatalogPriceForm">
414414
<form id="add-catalog-price-form"
415415
class="form-horizontal"
416+
th:object="${addCatalogPriceForm}"
416417
hx-target="#add-catalog-price"
417418
hx-disabled-elt="#add-catalog-price-btn"
418419
th:hx-patch="@{${INFO_SERIES_PAGE}(id=${seriesId})}">
419420
<div class="alert alert-danger text-center col-sm-8 col-sm-offset-3 hidden server-error-msg"
420421
th:text="#{t_server_error}">
421422
Server error
422423
</div>
423-
<div class="form-group form-group-sm">
424+
<div class="form-group form-group-sm"
425+
th:classappend="${isHtmx and #fields.hasErrors('catalogName') ? 'has-error' : ''}">
424426
<label for="price-catalog-name" class="control-label col-sm-3" th:text="#{t_catalog}">
425427
Catalog
426428
</label>
@@ -433,9 +435,19 @@ <h5 th:text="#{t_hidden_images}">Hidden images</h5>
433435
<option value="SOLOVYOV" th:text="#{t_solovyov}">Solovyov</option>
434436
<option value="ZAGORSKI" th:text="#{t_zagorski}">Zagorski</option>
435437
</select>
438+
<!--/*/
439+
<th:block th:if="${isHtmx}">
440+
<span id="price-catalog-name.errors"
441+
class="help-block"
442+
th:if="${#fields.hasErrors('catalogName')}"
443+
th:each="error : ${#fields.errors('catalogName')}" th:text="${error}">
444+
</span>
445+
</th:block>
446+
/*/-->
436447
</div>
437448
</div>
438-
<div class="form-group form-group-sm">
449+
<div class="form-group form-group-sm"
450+
th:classappend="${isHtmx and #fields.hasErrors('price') ? 'has-error' : ''}">
439451
<label for="catalog-price" class="control-label col-sm-3 required-field" th:text="#{t_price}">
440452
Price
441453
</label>
@@ -454,6 +466,17 @@ <h5 th:text="#{t_hidden_images}">Hidden images</h5>
454466
required="required" />
455467
</div>
456468
</div>
469+
<div class="col-sm-offset-3 col-sm-6">
470+
<!--/*/
471+
<th:block th:if="${isHtmx}">
472+
<span id="price.errors"
473+
class="help-block"
474+
th:if="${#fields.hasErrors('price')}"
475+
th:each="error : ${#fields.errors('price')}" th:text="${error}">
476+
</span>
477+
</th:block>
478+
/*/-->
479+
</div>
457480
</div>
458481
<div class="col-sm-offset-3 col-sm-4">
459482
<button id="add-catalog-price-btn"

0 commit comments

Comments
 (0)