Test form validation
Email: example@uproid.com
Password: @Test123
Password: @Test123
-
View example/lib/widgets/example/form.j2.html
-
Controller example/lib/controllers/home_controller.dart
Future<String> exampleForm() async {
if (rq.method == RequestMethods.POST) {
var loginForm = FormValidator(
name: 'loginForm',
rq: rq,
fields: {
'email': [
FieldValidator.isEmailField(),
FieldValidator.requiredField(),
FieldValidator.fieldLength(min: 5, max: 255)
],
'password': [
(value) {
return FieldValidateResult(
success: value.toString().isPassword,
error:
'Password is not valid, it most has [Number/Char(Upper+Lower)/?@#\$!%]',
);
},
FieldValidator.requiredField(),
FieldValidator.fieldLength(min: 8, max: 255)
],
},
);
var result = await loginForm.validateAndForm();
var loginResult = false;
if (result.result) {
var email = rq.get<String>('email', def: '');
var password = rq.get<String>('password', def: '');
if (email == 'example@uproid.com' && password == '@Test123') {
loginResult = true;
}
}
rq.addParams({
'loginForm': result.form,
'loginResult': loginResult,
});
}
return renderTemplate('example/form');
}