-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SAUL
committed
Oct 23, 2024
1 parent
aba6a1a
commit 21c3b6c
Showing
4 changed files
with
239 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
package ui.screens | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import cafe.adriel.voyager.core.screen.Screen | ||
import ui.components.forms.PasswordForm | ||
import ui.validators.passwordFormValidator | ||
|
||
class PasswordFormScreen : Screen { | ||
|
||
@Composable | ||
override fun Content() { | ||
PasswordForm() | ||
|
||
val formValidator = remember { passwordFormValidator() } | ||
|
||
val isFormValid by formValidator.isValid | ||
|
||
PasswordForm( | ||
formValidator, | ||
isFormValid, | ||
onSaveClick = {} | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ui.validators | ||
|
||
import core.form.FormField | ||
import core.form.FormFieldName | ||
import core.form.validation.* | ||
|
||
fun passwordFormValidator(): FormValidator { | ||
return FormValidator() | ||
.addField( | ||
PasswordFormFieldName.USERNAME, FormField( | ||
validator = Validator() | ||
.addRule(notNullRule(PasswordFormFieldName.USERNAME.fieldName)) | ||
.addRule(lengthRule(PasswordFormFieldName.USERNAME.fieldName, 1)) | ||
) | ||
) | ||
.addField( | ||
PasswordFormFieldName.EMAIL, FormField( | ||
validator = Validator() | ||
.addRule(notNullRule(PasswordFormFieldName.EMAIL.fieldName)) | ||
.addRule(lengthRule(PasswordFormFieldName.EMAIL.fieldName, 1)) | ||
.addRule(emailRule) | ||
) | ||
) | ||
.addField( | ||
PasswordFormFieldName.PASSWORD, FormField( | ||
validator = Validator() | ||
.addRule(notNullRule(PasswordFormFieldName.PASSWORD.fieldName)) | ||
.addRule(passwordRule) | ||
) | ||
) | ||
.addField( | ||
PasswordFormFieldName.NAME, FormField( | ||
validator = Validator() | ||
.addRule(notNullRule(PasswordFormFieldName.NAME.fieldName)) | ||
.addRule(lengthRule(PasswordFormFieldName.NAME.fieldName, 1)) | ||
) | ||
) | ||
.addField( | ||
PasswordFormFieldName.WEBSITE_URL, FormField( | ||
validator = Validator() | ||
.addRule(notNullRule(PasswordFormFieldName.WEBSITE_URL.fieldName)) | ||
.addRule(lengthRule(PasswordFormFieldName.WEBSITE_URL.fieldName, 1)) | ||
.addRule(urlRule) | ||
) | ||
) | ||
.addField( | ||
PasswordFormFieldName.WEBSITE_ICON_URL, FormField( | ||
validator = Validator() | ||
.addRule(notNullRule(PasswordFormFieldName.WEBSITE_ICON_URL.fieldName)) | ||
.addRule(lengthRule(PasswordFormFieldName.WEBSITE_ICON_URL.fieldName, 1)) | ||
.addRule(urlRule) | ||
) | ||
).validateAllFields() | ||
} | ||
|
||
enum class PasswordFormFieldName(val fieldName: String) : FormFieldName { | ||
USERNAME("Username"), | ||
EMAIL("Email"), | ||
PASSWORD("Password"), | ||
NAME("Name"), | ||
WEBSITE_URL("Website URL"), | ||
WEBSITE_ICON_URL("Website Icon URL"); | ||
} |