How to Validate Forms with Clean Architecture (You're Doing it Wrong)

preview_player
Показать описание
Learning clean architecture can be tough. In this video I'll show you how you can solve the very common problem of validating forms by properly following the clean architectural guidelines.

⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:

Subscribe to my FREE newsletter for regular Android, Kotlin & Architecture advice!

Join this channel to get access to perks:

Get the source code for this video here:

Join my Discord server:

You like my free content? Here you can buy me a coffee:
Рекомендации по теме
Комментарии
Автор

Thanks for including the test part. That's always missing in dev videos!

sideness
Автор

Hi Phil, Thank you for this great content. Just a quick revision when you do the following:
if(hasError) {
state = state.copy(
emailError = emailResult.errorMessage,
passwordError = passwordResult.errorMessage,
repeatedPasswordError = repeatedPasswordResult.errorMessage,
termsError = termsResult.errorMessage
)
return
}

The state should be modified regardless of an error here. While I was watching the video at the end you get the toast and the emailError is still not null because of hasError being false. So the state modification should get extracted out of that block and placed before the hasError check:
state = state.copy(
emailError = emailResult.errorMessage,
passwordError = passwordResult.errorMessage,
repeatedPasswordError = repeatedPasswordResult.errorMessage,
termsError = termsResult.errorMessage
)
if(hasError) { return }

lalobarrios
Автор

You speak calmly and you remind me of Bob Ross, but showing expertise in Android development. What a great video 😁

rileyfarro
Автор

I prefer to create an after text changed listener on the edit texts that saves all the edit texts each time any text is changed. All the text is then tested in the use case and the returned messages are reviewed within the UI with a "when" bracket that will only show one message at a time. When there are no messages to show, the last option in the "when" bracket will enable the button to be clickable.

s-w
Автор

Nice video bro 👌
I like the use of Channels, they seem quite good in a combination with Compose.

StevdzaSan
Автор

One of my favorites about kotlin is, its Sealed Class. And I think it suits best for this kind of case. I created sealed class with children of every possible outcome, make domain layer don't care about wording and let presentation layer map it.

AfriandiHaryanto
Автор

Great video.
Regarding unit testing, isn't it better to use interface impl pair for the use cases?
Also, when asserting values, when you use assertEquals, the first parameter should be the value you expect, and the second value should be the value that you test.
Regardless, when you test booleans, you can use assertTrue and assertFalse.

arielapp
Автор

I've mix this video and the "This Is My FAVORITE Error Handling Class" one to valid custom user input and it work greats !

Ayor
Автор

How do you handle a 'loading' state? When the submit button is pressed, I would like to show a spinner and disable all input fields

Rafael-hkpg
Автор

Your example shows that you are using strings in usecase.
I think what you missed is that we need to map useCase to presenter object.
Beacuse in standard compay project you would like to have strings in string resources.

LszcZ
Автор

Another quality tutorial from Phillip! Thank you man!

shrp
Автор

Setting error messages in the use case is definitely not clean architecture, interactor response should only contains litterals like boolean error flags, the presenter is responsible for error strings, and it's not in application layer.

adriencuisse
Автор

What is the way to make the error messages support translation? Context can not be passed in use cases since these are designed to be independent of the platform.

rokib
Автор

We should step into DDD with a solid Use Case in MVVM, then convert to vertical slice architecture with a few independently buildable and testable modules...then we are styling Phil.

mattgraves
Автор

unable to import mutableStateOf in my xml android project any alternative

taknikiniga
Автор

really really good video one gently critic the error message should disappear when the user is editing the input field. Thanks a lot for the video!! :))

sebastianpalm
Автор

Hii phil, thanks for the tutorial iam facing the issue like after succesful validation it is showing toast message pls provide me the solution.thanks

rohithkumar
Автор

Hey great Video,
how can I reset the Flow so I can validate the next inputs after

lucachrist
Автор

Excellent as always.
We could add on the TextFields a maxLines = 1 and singleLine = true otherwise we could have many lines or an '\n'

emmanuelpregnolato
Автор

Hello there, great and pretty complete video! Thank you for your hard work Philipp

I have a question: how do you End-to-End test it? I explicitly followed this video and the one with testing (linked to your Note app) and whenever I ask the test to click on the Submit button and check if I have a new Text() displayed (with the explicit error), my test fails since it doesn't seem to reload the layout. Did it already happen to somebody?

chips