How can I tell when all the fields on a layout are valid?

I want a big green checkmark

:heavy_check_mark:

to appear on a Layout when the user successfully completes all required data-entry.

How can I detect when every field is in a valid state?
(By ‘field’ I mean AbstractField components such as TextField & OptionGroup)

I understand adding validators to field. I have that working.

→ I am stuck on how to detect when the last invalid field is made valid by the user.

My first thought was to add the containing Layout as a listener to each field. Specifically, the
Property.ValueChangeListener
seemed like the right match. Unfortunately, the event passed (
Property.ValueChangeEvent
) has “getSource” or any other such mechanism. So I have no reference back to the field the user just used, so I cannot call “isValid” on that field.

What strategy would you suggest for tracking when the last invalid field is made valid?

–Basil Bourque

Well if you don’t want to use Form and its commit method, you could use the ComponentContainer (layout) as the listener . ComponentContainers have getChildIterator() method. You could then iterate all the child components of the layout and call isValid() for all of the fields.

What ValueChangeEvents are you listening for. They should have a source - if you listen to changes of fields, most fields actually send a Field.ValueChangeEvent for which the source is a Field. If you listen to changes of the underlying properties, you should get a reference to the property but not the field.