Browse Source

Re-format currency field in add/edit web forms

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.1-alpha
Pekka Helenius 4 years ago
parent
commit
22a0434300
3 changed files with 16 additions and 5 deletions
  1. +3
    -2
      bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java
  2. +6
    -1
      bookstore/src/main/resources/templates/bookadd.html
  3. +7
    -2
      bookstore/src/main/resources/templates/bookedit.html

+ 3
- 2
bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java View File

@ -11,9 +11,10 @@ import javax.validation.constraints.Size;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import com.fjordtek.bookstore.validation.CurrentYear;
import com.fjordtek.bookstore.annotation.CurrentYear;
import org.springframework.format.annotation.NumberFormat; import org.springframework.format.annotation.NumberFormat;
import org.springframework.format.annotation.NumberFormat.Style;
//import java.sql.Timestamp; //import java.sql.Timestamp;
//import javax.validation.constraints.PastOrPresent; //import javax.validation.constraints.PastOrPresent;
@ -114,7 +115,7 @@ public class Book {
) )
private String isbn; private String isbn;
@NumberFormat(pattern = "#,###,###,###.##")
@NumberFormat(style = Style.NUMBER, pattern = "#,###.###")
@Digits( @Digits(
integer = 3, fraction = 2, integer = 3, fraction = 2,
message = "Invalid price, possibly too many decimals" message = "Invalid price, possibly too many decimals"


+ 6
- 1
bookstore/src/main/resources/templates/bookadd.html View File

@ -37,7 +37,12 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="fname">Price</label> <label for="fname">Price</label>
<input class="form-control" type="text" th:field="*{price}" placeholder="Book price"/>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"></div>
</div>
<input class="form-control" type="text" th:field="*{price}" placeholder="Book price"/>
</div>
<small class="form-text text-muted">Set book price</small> <small class="form-text text-muted">Set book price</small>
<div class="alert alert-danger mt-2" th:if="${#fields.hasErrors('price')}" th:errors="*{price}">Invalid price</div> <div class="alert alert-danger mt-2" th:if="${#fields.hasErrors('price')}" th:errors="*{price}">Invalid price</div>
</div> </div>


+ 7
- 2
bookstore/src/main/resources/templates/bookedit.html View File

@ -36,8 +36,13 @@
<div class="alert alert-danger mt-2" th:if="${#fields.hasErrors('year')}" th:errors="*{year}">Invalid year</div> <div class="alert alert-danger mt-2" th:if="${#fields.hasErrors('year')}" th:errors="*{year}">Invalid year</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="BookPrice">Price</label><br>
<input class="form-control" type="text" th:field="*{price}" placeholder="Book price"/>
<label for="fname">Price</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"></div>
</div>
<input class="form-control" type="text" th:field="*{price}" placeholder="Book price"/>
</div>
<small class="form-text text-muted">Set book price</small> <small class="form-text text-muted">Set book price</small>
<div class="alert alert-danger mt-2" th:if="${#fields.hasErrors('price')}" th:errors="*{price}">Invalid price</div> <div class="alert alert-danger mt-2" th:if="${#fields.hasErrors('price')}" th:errors="*{price}">Invalid price</div>
</div> </div>


Loading…
Cancel
Save