How do I clear a form (FormLayout)?

How can a FormLayout be cleared?

Assuming all fields have been bound through a Binder, you could simply call binder.getFields().forEach(f -> f.clear());

If you want to actually remove the fields, you’ll need to remove each binding from the Binder or create a new Binder object. Then remove them from the layout using formLayout.removeAll().

Thomas Mattsson:
Assuming all fields have been bound through a Binder, you could simply call binder.getFields().forEach(f -> f.clear());

If you want to actually remove the fields, you’ll need to remove each binding from the Binder or create a new Binder object. Then remove them from the layout using formLayout.removeAll().

I have a similar problem … I have a product registration screen, and after typing the product data I click save and the product goes to a grid … when I want to register a second product, the data for the first product is stored in the textfields … I would like that when the first product was saved in the grid, the fields fields were automatically cleared, they recommended me to use Binder … but I couldn’t do it … can you explain to me how I do it in my case?

Thomas Mattsson:
Assuming all fields have been bound through a Binder, you could simply call binder.getFields().forEach(f -> f.clear());

If you want to actually remove the fields, you’ll need to remove each binding from the Binder or create a new Binder object. Then remove them from the layout using formLayout.removeAll().

@Thomas Mattsson
In my case only the first field gets cleared, and I end up in NullPointerException when invoking clear().

https://vaadin.com/forum/thread/18529163/problem-after-editing-product-in-the-grid

Guys, good morning, I have a problem that is described in the link above. In case anyone can help me, it is very similar to the one described by Shadi Khani.

I apologize for putting another discussion in here, but as it is a similar subject, I thought there would be no problems.

Thank you all