web-components icon indicating copy to clipboard operation
web-components copied to clipboard

[vaadin-checkbox] Is always propagated in a login form's custom area

Open knoobie opened this issue 1 year ago • 2 comments

Description

Adding a CheckBox to a Login Overlay's custom area always sends the value to the server - even tho the checkbox is unchecked / never clicked. It does not matter if I use the default value of "on" or a custom value - the value is always send to the server, making the CheckBox useless.

Expected outcome

CheckBox's value is only send if the checkbox is checked.

Minimal reproducible example

LoginOverlay loginOverlay = new LoginOverlay();
var checkbox = new Checkbox("Test");
checkbox.getElement().setAttribute("name", "test");
loginOverlay.getCustomFormArea().add(checkbox);

Steps to reproduce

  1. Fill out form
  2. Press Submit
  3. See network tab: request contains test=on (even tho the checkbox is NOT checked)

Environment

Vaadin version(s): latest

knoobie avatar Oct 16 '24 11:10 knoobie

The on is a default value that checkbox has. In native <form> it isn't submitted when unchecked, see MDN docs. We should update the following logic in LoginMixin to detect the unchecked checkbox and don't submit it:

https://github.com/vaadin/web-components/blob/79ecca94f4b0dca53e860100b2b0ccaea1b42e42/packages/login/src/vaadin-login-form-mixin.js#L65-L67

web-padawan avatar Oct 16 '24 11:10 web-padawan

In native form it isn't submitted when unchecked, see MDN docs.

Thanks! That was exactly the page I was also consulting which left me wondering why the form contained the value :)

knoobie avatar Oct 16 '24 11:10 knoobie