1

I am wondering if I can add buttons that will allow me to increase and decrease the value of int variable. Something similar to the image below, so user wouldn't have to type integers from keyboard everytime. Is it possible?

enter image description here

SubmitController

@Controller
public class SubmitController {

@GetMapping("edit/{id}")
    public String showUpdateForm(@PathVariable ("id") long id, Model model) {
        Submit submit = submitRepo.findById(id)
                .orElseThrow(() -> new IllegalArgumentException("Invalid ID: " + id));
        List<String> rank = Arrays.asList("I", "II", "III", "IV", "V", "VI", "X" );
        model.addAttribute("rank", rank);
        model.addAttribute("submit", submit);
        return "submit_update";
    }

    @PostMapping("update/{id}")
    @Transactional
    public String updateSubmit(@PathVariable ("id") long id, @Valid Submit submit, BindingResult result, Model model) {

        if (result.hasErrors()) {
            submit.setId(id);
            return "submit_update";
        }

        submitService.increase(submit);
        submitRepo.save(submit);
        model.addAttribute("submit", submitRepo.findAll());
        return "redirect:/list";
    }
}

Submit

@Entity
public class Submit {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    private String rank;
    private String email;
    private String leader;
    private Integer score = 0;
    private Integer wins = 0;
    private Integer loses = 0;
    private Integer draws = 0;
Cobra
  • 31
  • 9
  • 1
    This question may also be of use: [Customizing Increment Arrows on Input of Type Number Using CSS](https://stackoverflow.com/questions/45396280/customizing-increment-arrows-on-input-of-type-number-using-css). – andrewJames May 08 '21 at 13:29
  • 1
    Do you want custom arrows, or is using the `number` type in HTML also ok? See https://www.w3schools.com/tags/att_input_type_number.asp – Wim Deblauwe May 08 '21 at 16:10
  • Thank you for your comments. Well, it works fine with HTML's number type. It does the job as it should, so I'm ok with it, thank you :) – Cobra May 08 '21 at 16:58

0 Answers0