I'm building a form where some validation has to h...
# compose
c
I'm building a form where some validation has to happen after the submit button is hit. If an error occurs I want to scroll the user up to the form item that has an error. What apis would be best to do that? The list is long (like 20 items) but it's not lazy if that helps in regards to a rec.
e
Since its not a lazy layout, you can attach a
BringIntoViewRequester
to each “form field” and keep the reference map of “field” to BIVR. For the field which fails validation, use its BIVR to request it on the screen. If its somewhere in a scrollable layout, it should just scroll on screen.
Requesting focus (
FocusRequester
) on the field might also work (iirc it uses BIVR under the hood but I am not sure about this one)
For lazy layouts BIVR would probably not work. For that, you can just keep a map of field to item “key”. On failed validation, you can then scroll to the item via lazyListState.animateScrollToItem or something.
m
I had an usecase (somewhat) like this, long form with various different sections each doing it’s own validation. I use
LazyColumn
. each section had separate
ViewModel
and exposed the error, upon validating I scroll to first section with error using
animateScrollToItem
form with 20 items is a long one, any reason to not make it lazy?
on
Column
you would need to scroll by
px
right?