- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,这是我的表单小部件的相关部分。
// email
section = Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// heading section
Container(
width: _formSectionHeadingSize.width,
height: _formSectionHeadingSize.height,
child: Center(
child: Text(
"Your Email Address",
style: Theme.of(context).textTheme.headline,
),
),
),
// description
Container(
width: _formSectionDescriptionSize.width,
height: _formSectionDescriptionSize.height,
padding: const EdgeInsets.all(_sectionPadding),
child: Text(
"Your email address will be used to send you purchase receipts, updates, and other information.",
style: Theme.of(context).textTheme.body1,
),
),
// body
Container(
width: _formSectionBodySize.width,
height: _formSectionBodySize.height,
padding: const EdgeInsets.all(_sectionPadding),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
controller: _email,
focusNode: _emailFocus,
textInputAction: TextInputAction.done,
keyboardType: TextInputType.emailAddress,
onChanged: (value) {
BlocProvider.of<RegistrationFormBloc>(context)
.add(EmailChanged(email: value));
},
onFieldSubmitted: (value) {
FocusScope.of(context).unfocus();
BlocProvider.of<RegistrationFormBloc>(context)
.add(EmailChanged(email: value));
},
decoration: InputDecoration(
labelText: "Email Address",
labelStyle: Theme.of(context).textTheme.body1,
hintText: "example@example.com",
errorText: currentState.emailError,
),
),
],
),
),
// navigation
Container(
width: _bottomNavigationSize.width,
height: _bottomNavigationSize.height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
FlatButton(
child: Text(
"Back",
style: Theme.of(context).textTheme.body1,
),
onPressed: this._showPreviousSection,
),
FlatButton(
child: Text(
"Next",
style: Theme.of(context).textTheme.body1,
),
onPressed: currentState.emailFieldsAreValid()
? this._showNextSection
: null,
),
],
),
),
],
);
EmailChanged
事件到我的 RegistrationFormBloc 来验证值。这是集团逻辑。
@override
Stream<RegistrationState> mapEventToState(RegistrationEvent event) async* {
// The first name was updated.
if (event is FirstNameChanged) {
yield await this._onFirstNameChanged(event);
}
// Last name was changed
if (event is LastNameChanged) {
yield await this._onLastNameChanged(event);
}
// email was changed
if (event is EmailChanged) {
yield await this._onEmailChanged(event);
}
// Password was changed
if (event is PasswordChanged) {
yield await this._onPasswordChanged(event);
}
// The terms of service accept status has been changed
if (event is TermsAcceptanceChanged) {
yield await this._onTermsAccptanceChanged(event);
}
if (event is PrivacyAcceptanceChanged) {
yield await this._onPrivacyAcceptanceChanged(event);
}
// The form is submitted
if (event is FormSubmitted) {
yield RegistrationProcessing();
yield await this._onFormSubmitted(event);
}
// date of birth has been changed.
if (event is DateOfBirthChanged) {
yield await this._onDateOfBirthChanged(event);
}
// form started
if (event is FormStarted) {
yield await this._onFormStarted(event);
}
// form canceled by the user
if (event is FormCanceled) {
yield await this._onFormCanceled(event);
yield RegistrationUninitialized();
}
}
_onEmailChanged()
的 Logo 功能。
Future<RegistrationState> _onEmailChanged(EmailChanged event) async {
return RegistrationInProgress(
firstName: state.firstName,
firstNameError: state.firstNameError,
lastName: state.lastName,
lastNameError: state.lastNameError,
email: event.email,
emailError: await this._validateEmail(event.email),
password: state.password,
passwordError: state.passwordError,
dob: state.dob,
dobError: state.dobError,
acceptedTerms: state.acceptedTerms,
acceptedPrivacy: state.acceptedPrivacy,
);
}
emailError
field 。这是
validateEmail()
的代码功能。
Future<String> _validateEmail(String email) async {
// make sure the email is not empty.
if (QuiverString.isBlank(email)) {
return "This field is required";
}
// make sure the email is of a valid form
if (!this._emailIsValidForm(email)) {
return "Email is invalid.";
}
// make sure the email is not already taken by another account.
if ( !await this._emailIsAvailable(email)) {
return "email already in use";
}
return null;
}
emailIsValidForm()
函数(因为返回的响应错误)。这是该功能的代码。我使用
EmailValidator
包以验证电子邮件。
bool _emailIsValidForm(String email) {
return EmailValidator.validate(email, ALLOW_TOP_LEVEL_DOMAINS, ALLOW_INTERNATIONAL);
}
abstract class RegistrationState extends Equatable {
final String firstName;
final String firstNameError;
final String lastName;
final String lastNameError;
final String email;
final String emailError;
final String password;
final String passwordError;
final DateTime dob;
final String dobError;
final bool acceptedTerms;
final bool acceptedPrivacy;
final String registrationError;
@override
List<Object> get props => [
firstName,
firstNameError,
lastName,
lastNameError,
email,
emailError,
password,
passwordError,
dob,
dobError,
acceptedTerms,
acceptedPrivacy,
registrationError
];
const RegistrationState({
@required this.firstName,
@required this.firstNameError,
@required this.lastName,
@required this.lastNameError,
@required this.email,
@required this.emailError,
@required this.password,
@required this.passwordError,
@required this.dob,
@required this.dobError,
@required this.acceptedTerms,
@required this.acceptedPrivacy,
this.registrationError,
});
// make sure the name fields are valid.
bool nameFieldsAreValid() {
return (firstNameError == null) && (lastNameError == null) && (firstName != null) && (lastName != null);
}
// checks if the email field is valid.
bool emailFieldsAreValid() {
return (emailError == null) && (email != null);
}
// make sure the password fields are valid.
bool passwordFieldsAreVaid() {
return (passwordError == null) && (password != null);
}
// chekcs to see if the date of birth is valid.
bool dobFiedsAreValid() {
return ((dob != null) && (dobError == null));
}
// validates that all the terms have been accepted.
bool allTermsAccepted() {
return (acceptedTerms && acceptedPrivacy);
}
}
/// Uninitialized State
///
/// The Registration has not been invoked.
class RegistrationUninitialized extends RegistrationState {
RegistrationUninitialized()
: super(
firstName: null,
firstNameError: null,
lastName: null,
lastNameError: null,
email: null,
emailError: null,
password: null,
passwordError: null,
dob: null,
dobError: null,
acceptedTerms: false,
acceptedPrivacy: false,
registrationError: null);
}
/// Started State
///
/// The Registration process has been initiated and is in progress.
class RegistrationStarted extends RegistrationState {
RegistrationStarted()
: super(
firstName: null,
firstNameError: null,
lastName: null,
lastNameError: null,
email: null,
emailError: null,
password: null,
passwordError: null,
dob: null,
dobError: null,
acceptedTerms: false,
acceptedPrivacy: false,
registrationError: null);
}
/// InProgress State
///
/// The Registration application is in progress.
class RegistrationInProgress extends RegistrationState {
RegistrationInProgress(
{@required firstName,
@required firstNameError,
String lastName,
String lastNameError,
@required email,
@required String emailError,
@required String password,
@required String passwordError,
@required DateTime dob,
@required String dobError,
@required bool acceptedTerms,
@required bool acceptedPrivacy})
: super(
firstName: firstName,
firstNameError: firstNameError,
lastName: lastName,
lastNameError: lastNameError,
email: email,
emailError: emailError,
password: password,
passwordError: passwordError,
dob: dob,
dobError: dobError,
acceptedTerms: acceptedTerms,
acceptedPrivacy: acceptedPrivacy,
registrationError: null);
}
/// Completed State
///
/// The Registration has been completed successfully.
class RegistrationCompleted extends RegistrationState {
RegistrationCompleted(
{@required firstName,
@required firstNameError,
String lastName,
String lastNameError,
@required email,
@required String emailError,
@required String password,
@required String passwordError,
@required DateTime dob,
@required String dobError,
@required bool acceptedTerms,
@required bool acceptedPrivacy})
: super(
firstName: firstName,
firstNameError: firstNameError,
lastName: lastName,
lastNameError: lastNameError,
email: email,
emailError: emailError,
password: password,
passwordError: passwordError,
dob: dob,
dobError: dobError,
acceptedTerms: acceptedTerms,
acceptedPrivacy: acceptedPrivacy,
registrationError: null);
}
/// Rejected State
///
/// The registration has been rejected
class RegistrationRejected extends RegistrationState {
RegistrationRejected(
{@required firstName,
@required firstNameError,
String lastName,
String lastNameError,
@required email,
@required String emailError,
@required String password,
@required String passwordError,
@required DateTime dob,
@required String dobError,
@required bool acceptedTerms,
@required bool acceptedPrivacy,
@required String registrationError})
: super(
firstName: firstName,
firstNameError: firstNameError,
lastName: lastName,
lastNameError: lastNameError,
email: email,
emailError: emailError,
password: password,
passwordError: passwordError,
dob: dob,
dobError: dobError,
acceptedTerms: acceptedTerms,
acceptedPrivacy: acceptedPrivacy,
registrationError: registrationError);
}
/// Canceled State
///
/// The registration was canceled by the user.
class RegistrationCanceled extends RegistrationState {
RegistrationCanceled(
{@required firstName,
@required String lastName,
@required email,
@required DateTime dob,})
: super(
firstName: firstName,
firstNameError: null,
lastName: lastName,
lastNameError: null,
email: email,
emailError: null,
password: null,
passwordError: null,
dob: dob,
dobError: null,
acceptedTerms: true,
acceptedPrivacy: true,
registrationError: null);
}
/// Processing State
///
/// The registration is being processed by the server.
class RegistrationProcessing extends RegistrationState {}
abstract class RegistrationEvent extends Equatable {
const RegistrationEvent();
@override
List<Object> get props => [];
}
class FirstNameChanged extends RegistrationEvent {
final String firstName;
const FirstNameChanged({@required this.firstName});
@override
List<Object> get props => [firstName];
@override
String toString() {
return "FirstNameChanged Event: {\n$firstName\n}";
}
}
class LastNameChanged extends RegistrationEvent {
final String lastName;
const LastNameChanged({@required this.lastName});
@override
List<Object> get props => [lastName];
@override
String toString() {
return "LastNameChanged Event: {\n$lastName\n}";
}
}
class EmailChanged extends RegistrationEvent {
final String email;
const EmailChanged({@required this.email});
@override
List<Object> get props => [email];
@override
String toString() {
return "EmailChanged Event: {\n$email\n}";
}
}
class PasswordChanged extends RegistrationEvent {
final String password;
const PasswordChanged({@required this.password});
@override
List<Object> get props => [password];
@override
String toString() {
return "PasswordChanged Event: {\n${password.replaceRange(0, password.length - 1, "*")}\n}";
}
}
class TermsAcceptanceChanged extends RegistrationEvent {
final bool acceptTerms;
const TermsAcceptanceChanged({@required this.acceptTerms});
@override
List<Object> get props => [acceptTerms];
@override
String toString() {
String msg = acceptTerms ? "Accepted" : "Denied";
return "TermsAcceptanceChanged Event: {\n$msg\n}";
}
}
class PrivacyAcceptanceChanged extends RegistrationEvent {
final bool acceptPrivacy;
const PrivacyAcceptanceChanged({@required this.acceptPrivacy});
@override
List<Object> get props => [acceptPrivacy];
@override
String toString() {
String msg = acceptPrivacy ? "Accepted" : "Denied";
return "PrivacyAcceptanceChanged Event: {\n$msg\n}";
}
}
class FormSubmitted extends RegistrationEvent {
@override
String toString() {
return "FormSubmitted Event: {}";
}
}
class FormStarted extends RegistrationEvent {
@override
String toString() {
return "FormStarted Event: {}";
}
}
class FormCanceled extends RegistrationEvent {
@override
String toString() {
return "FormCanceled Event: {}";
}
}
class DateOfBirthChanged extends RegistrationEvent {
final DateTime dob;
const DateOfBirthChanged({@required this.dob});
@override
List<Object> get props => [dob];
@override
String toString() {
DateFormat format = DateFormat.yMd();
return "DateOfBirthChanged Event: {\n${format.format(dob)}\n}";
}
}
class FormProcessing extends RegistrationEvent {
@override
String toString() {
return "FormProcessing Event: {}";
}
}
_onFirstNameChange()
Future<RegistrationState> _onFirstNameChanged(FirstNameChanged event) async {
return RegistrationInProgress(
firstName: event.firstName,
firstNameError: this._validateFirstName(event.firstName),
lastName: state.lastName,
lastNameError: state.lastNameError,
email: state.email,
emailError: state.emailError,
password: state.password,
passwordError: state.passwordError,
dob: state.dob,
dobError: state.dobError,
acceptedTerms: state.acceptedTerms,
acceptedPrivacy: state.acceptedPrivacy);
}
_validateFirstName()
方法。
String _validateFirstName(String fName) {
return QuiverString.isBlank(fName) ? "This field is required." : null;
}
@override
Widget build(BuildContext context) {
return BlocBuilder<RegistrationFormBloc, RegistrationState>(
builder: (BuildContext context, RegistrationState state) {
return Scaffold(
body: GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// the form itself.
_showFormSection(state),
// the exit button
Center(
child: FlatButton(
child: Text("Cancel"),
onPressed: () {
BlocProvider.of<RegistrationFormBloc>(context)
.add(FormCanceled());
Navigator.pop(context);
},
),
),
],
),
),
),
),
);
},
);
}
Widget _showFormSection(RegistrationState currentState) {
Widget section;
switch (_pageIndex) {
case 0:
section = NameWidget();
break;
case 1:
// email
section = Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// heading section
Container(
width: _formSectionHeadingSize.width,
height: _formSectionHeadingSize.height,
child: Center(
child: Text(
"Your Email Address",
style: Theme.of(context).textTheme.headline,
),
),
),
// description
Container(
width: _formSectionDescriptionSize.width,
height: _formSectionDescriptionSize.height,
padding: const EdgeInsets.all(_sectionPadding),
child: Text(
"Your email address will be used to send you purchase receipts, updates, and other information.",
style: Theme.of(context).textTheme.body1,
),
),
// body
Container(
width: _formSectionBodySize.width,
height: _formSectionBodySize.height,
padding: const EdgeInsets.all(_sectionPadding),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
controller: _email,
focusNode: _emailFocus,
textInputAction: TextInputAction.done,
keyboardType: TextInputType.emailAddress,
onChanged: (value) {
BlocProvider.of<RegistrationFormBloc>(context)
.add(EmailChanged(email: value));
},
onFieldSubmitted: (value) {
FocusScope.of(context).unfocus();
BlocProvider.of<RegistrationFormBloc>(context)
.add(EmailChanged(email: value));
},
decoration: InputDecoration(
labelText: "Email Address",
labelStyle: Theme.of(context).textTheme.body1,
hintText: "example@example.com",
errorText: currentState.emailError,
),
),
],
),
),
// navigation
Container(
width: _bottomNavigationSize.width,
height: _bottomNavigationSize.height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
FlatButton(
child: Text(
"Back",
style: Theme.of(context).textTheme.body1,
),
onPressed: this._showPreviousSection,
),
FlatButton(
child: Text(
"Next",
style: Theme.of(context).textTheme.body1,
),
onPressed: currentState.emailFieldsAreValid()
? this._showNextSection
: null,
),
],
),
),
],
);
break;
case 2:
// password
section = PasswordWidget();
break;
case 3:
// date of birth
section = DobWidget();
break;
case 4:
// terms section
section = TermsWidget();
break;
}
return section;
}
// show the next section.
void _showNextSection() {
if (_pageIndex < 4) {
setState(() {
_pageIndex++;
});
}
}
// show the previous section
void _showPreviousSection() {
if (_pageIndex > 0) {
setState(() {
_pageIndex--;
});
}
}
最佳答案
在 onchanged 中,将 value.trim() 传递给事件。有时,在您输入您的电子邮件后,inputtext 中有尾随空格,要在验证时删除它,请使用函数 trim 以便删除该空格。
关于flutter - 电子邮件验证不随电子邮件文本字段更改而更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60364930/
在 JSF2 应用程序中遇到验证属性的问题时,有两种主要方法。 使用 Annotation 在 ManagedBean 上定义验证 @ManagedBean public class MyBean {
我想实现一个不常见的功能,我认为 jquery 验证插件将是最好的方法(如果您在没有插件的情况下建议和回答,我们也会欢迎)。我想在用户在输入字段中输入正确的单词后立即隐藏表单。我试过这个: $("
我有几个下拉菜单(类名为month_dropdown),并且下拉菜单的数量不是恒定的。我怎样才能为它们实现 NotEqual 验证。我正在使用 jQuery 验证插件。 这就是我写的 - jQuery
我设法制作了这个网址验证代码并且它起作用了。但我面临着一个问题。我认为 stackoverflow 是获得解决方案的最佳场所。 function url_followers(){ var url=do
我目前正在使用后端服务,该服务允许用户在客户端应用程序上使用 Google Games 库登录。 用户可以通过他们的 gplay ID 向我们发送信息,以便登录或恢复旧帐户。用户向我们发送以下内容,包
我正在尝试验证输入以查看它是否是有效的 IP 地址(可能是部分地址)。 可接受的输入:172、172.112、172.112.113、172.112.113.114 Not Acceptable 输入
我从 Mongoose 验证中得到这条消息: 'Validator failed for path phone with value ``' 这不应该发生,因为不需要电话。 这是我的模型架构: var
我一直在尝试使用Python-LDAP (版本 2.4.19)在 MacOS X 10.9.5 和 Python 2.7.9 下 我想在调用 .start_tls_s() 后验证与给定 LDAP 服务
我正在处理一个仅与 IE6 兼容的旧 javascript 项目(抱歉...),我想仅在 VS 2017 中禁用此项目的 ESLint/CSLint/Javascript 验证/CSS 验证。 我知道
我正在寻找一种方法来验证 Spring 命令 bean 中的 java.lang.Double 字段的最大值和最小值(一个值必须位于给定的值范围之间),例如, public final class W
我正在尝试在 springfuse(JavaEE 6 + Spring Framework (针对 Jetty、Tomcat、JBoss 等)) 和 maven 的帮助下构建我的 webapps 工作
我试图在我们的项目中使用 scalaz 验证,但遇到了以下情况: def rate(username: String, params: Map[String, String]): Validation
我有一个像这样的 Yaml 文件 name: hhh_aaa_bbb arguments: - !argument name: inputsss des
我有一个表单,人们可以单击并向表单添加字段,并且我需要让它在单击时验证这些字段中的值。 假设我单击它两次并获取 2 个独立的字段集,我需要旋转 % 以确保它在保存时等于 100。 我已放入此函数以使其
在我的页面中有一个选项可以创建新的日期字段输入框。用户可以根据需要创建尽可能多的“截止日期”和“起始日期”框。就像, 日期_to1 || date_from1 日期到2 ||日期_from2 date
我有一个像这样的 Yaml 文件 name: hhh_aaa_bbb arguments: - !argument name: inputsss des
有没有办法在动态字段上使用 jquery 验证表单。 我想将其设置为必填字段 我正在使用 Jsp 动态创建表单字段。 喜欢 等等...... 我想使用必需的表单字段验证此表单字段。 最佳答
嗨,任何人都可以通过提供 JavaScript 代码来帮助我验证用户名文本框不应包含数字,它只能包含一个字符。 最佳答案 使用正则表达式: (\d)+ 如果找到匹配项,则字符串中就有一个数字。 关于J
我有两个输入字段holidayDate和Description(id=tags) $(document).ready(function() {
我遇到了这个问题,这些验证从电子邮件验证部分开始就停止工作。 我只是不明白为什么即使经过几天的观察,只是想知道是否有人可以在这里指出我的错误? Javascript部分: function valid
我是一名优秀的程序员,十分优秀!