11import * as React from "react" ;
2+ import { FormattedMessage } from "react-intl" ;
23import { Field , FormProps } from "redux-form" ;
34const { reduxForm } = require ( "redux-form" ) ;
45import {
5- aol , email , matchedPwd , maxLength , minLength , minValue ,
6- numberType , renderField , required , tooOld
6+ aol , CustomField , email , matchedPwd , maxLength , minLength ,
7+ minValue , numberType , required , tooOld
78} from "../helpers/FormHelper" ;
89
910export interface IFormData {
@@ -18,21 +19,63 @@ interface IProps {
1819 onSubmit : ( values : IFormData ) => Promise < any > ;
1920}
2021
22+ /*tslint:disable:jsx-no-multiline-js*/
2123class RegisterForm extends React . Component < FormProps < IFormData , IProps , null > & IProps , null > {
2224 public render ( ) : JSX . Element {
2325 const { handleSubmit, pristine, reset, submitting} = this . props ;
2426
2527 return (
2628 < form onSubmit = { handleSubmit } >
27- < Field name = "username" type = "text" component = { renderField } label = "Username" validate = { [ required , maxLength ( 15 ) ] } />
28- < Field name = "password" type = "password" component = { renderField } label = "Password" validate = { [ required , minLength ( 8 ) ] } />
29- < Field name = "confirmPassword" type = "password" component = { renderField } label = "Confirm Password" validate = { [ required , matchedPwd ] } />
30- < Field name = "email" type = "email" component = { renderField } label = "Email" validate = { email } warn = { aol } />
31- < Field name = "age" type = "number" component = { renderField } label = "Age" validate = { [ required , numberType , minValue ( 18 ) ] } warn = { tooOld } />
29+ < Field
30+ name = "username"
31+ type = "text"
32+ component = { CustomField }
33+ languageId = "username"
34+ defaultMessage = "Username"
35+ validate = { [ required ( "username.required" , "Username is required" ) , maxLength ( "characters.max" , "Must be {max} characters or less" ) ( 15 ) ] }
36+ />
37+ < Field
38+ name = "password"
39+ type = "password"
40+ component = { CustomField }
41+ languageId = "password"
42+ defaultMessage = "Password"
43+ validate = { [ required ( "password.required" , "Password is required" ) , minLength ( "characters.min" , "Must be {min} characters or more" ) ( 8 ) ] }
44+ />
45+ < Field
46+ name = "confirmPassword"
47+ type = "password"
48+ component = { CustomField }
49+ languageId = "confirmpassword"
50+ defaultMessage = "Confirm Password"
51+ validate = { [ required ( "confirmpassword.required" , "Please confirm your password" ) , matchedPwd ( "password.unmatched" , "Passwords are not matched" ) ] }
52+ />
53+ < Field
54+ name = "email"
55+ type = "email"
56+ component = { CustomField }
57+ languageId = "email"
58+ defaultMessage = "Email"
59+ validate = { email ( "email.invalid" , "Invalid email format" ) }
60+ warn = { aol ( "email.aol" , "Really? You still use AOL for your email?" ) }
61+ />
62+ < Field
63+ name = "age"
64+ type = "number"
65+ component = { CustomField }
66+ languageId = "age"
67+ defaultMessage = "Age"
68+ validate = { [
69+ required ( "age.required" , "Age is required" ) ,
70+ numberType ( "field.numbertype" , "Must be a number" ) ,
71+ minValue ( "register.minage" , "You must be at least {min} years old!" ) ( 18 )
72+ ] }
73+ warn = { tooOld ( "register.tooold" , "You are too old for this!" ) }
74+ />
3275 < div >
33- < button type = "submit" disabled = { submitting } > Submit</ button >
76+ < button type = "submit" disabled = { submitting } > < FormattedMessage id = "submit" defaultMessage = " Submit" /> </ button >
3477 < button type = "button" disabled = { pristine || submitting } onClick = { reset } style = { { marginLeft : 10 } } >
35- Clear Values
78+ < FormattedMessage id = "form.clearvalues" defaultMessage = " Clear Values" />
3679 </ button >
3780 </ div >
3881 </ form >
0 commit comments