Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 带有react bootstrap样式的Formik_Reactjs_React Bootstrap_Formik - Fatal编程技术网

Reactjs 带有react bootstrap样式的Formik

Reactjs 带有react bootstrap样式的Formik,reactjs,react-bootstrap,formik,Reactjs,React Bootstrap,Formik,我正在尝试将Formik与我的react应用程序一起使用 我有react bootstrap,我正试图找出如何使用bootstrap样式设置窗体组件的样式 我的表格是: // Render Prop import React from 'react'; import { Link } from 'react-router-dom'; import { Formik, Form, Field, ErrorMessage } from 'formik'; import { Badge, Butto

我正在尝试将Formik与我的react应用程序一起使用

我有react bootstrap,我正试图找出如何使用bootstrap样式设置窗体组件的样式

我的表格是:

// Render Prop
import React from 'react';
import { Link } from 'react-router-dom';

import { Formik, Form, Field, ErrorMessage } from 'formik';
import { Badge, Button, Col, Feedback, FormControl, FormGroup, FormLabel, InputGroup } from 'react-bootstrap';
import * as Yup from 'yup';

const style1 = {
    width: '60%',
    margin: 'auto'
}

const style2 = {
    paddingTop: '2em',
}

const style3 = {
    marginRight: '2em'
}

class Basic extends React.Component {
    render() {
        return (
            <Formik
                initialValues={{
                    firstName: '',
                    lastName: '',
                    email: '',
                    role: '',
                    password: '',
                    confirmPassword: '',
                    consent: false
                }}
                validationSchema={Yup.object().shape({
                    firstName: Yup.string()
                        .required('First Name is required'),
                    lastName: Yup.string()
                        .required('Last Name is required'),
                    email: Yup.string()
                        .email('Email is invalid')
                        .required('Email is required'),
                    role: Yup.string()
                        .required('It will help us get started if we know a little about your background'),    
                    password: Yup.string()
                        .min(6, 'Password must be at least 6 characters')
                        .required('Password is required'),
                    confirmPassword:  Yup.string()
                        .oneOf([Yup.ref('password'), null], 'Passwords must match')
                        .required('Confirm Password is required')
                })}

                onSubmit={fields => {
                    alert('SUCCESS!! :-)\n\n' + JSON.stringify(fields, null, 4))
                }}
                render={({ errors, status, touched }) => (

                    <Form style={style1}>
                    <h1 style={style2}>Get Started</h1>
                        <div className="form-group">
                            <label htmlFor="firstName">First Name</label>
                            <Field name="firstName" type="text" className={'form-control' + (errors.firstName && touched.firstName ? ' is-invalid' : '')} />
                            <ErrorMessage name="firstName" component="div" className="invalid-feedback" />
                        </div>
                        <div className="form-group">
                            <label htmlFor="lastName">Last Name</label>
                            <Field name="lastName" type="text" className={'form-control' + (errors.lastName && touched.lastName ? ' is-invalid' : '')} />
                            <ErrorMessage name="lastName" component="div" className="invalid-feedback" />
                        </div>
                        <div className="form-group">
                            <label htmlFor="email">Email</label>
                            <Field name="email" type="text" placeholder="Please use your work email address" className={'form-control' + (errors.email && touched.email ? ' is-invalid' : '')} />
                            <ErrorMessage name="email" component="div" className="invalid-feedback" />
                        </div>

                        <div className="form-group">
                            <label htmlFor="role">Which role best describes yours?</label>
                            <Field name="role" type="text"  placeholder="eg, academic, industry R&D, policy, funder" className={'form-control' + (errors.role && touched.role ? ' is-invalid' : '')} >
                            </Field>
                            <ErrorMessage name="role" component="div" className="invalid-feedback" />
                        </div>
                        <div className="form-group">
                            <label htmlFor="password">Password</label>
                            <Field name="password" type="password" className={'form-control' + (errors.password && touched.password ? ' is-invalid' : '')} />
                            <ErrorMessage name="password" component="div" className="invalid-feedback" />
                        </div>
                        <div className="form-group">
                            <label htmlFor="confirmPassword">Confirm Password</label>
                            <Field name="confirmPassword" type="password" className={'form-control' + (errors.confirmPassword && touched.confirmPassword ? ' is-invalid' : '')} />
                            <ErrorMessage name="confirmPassword" component="div" className="invalid-feedback" />
                        </div>

                        <div className="form-group">
                        <Field component="select" name="color">
  <option value="red">Red</option>
  <option value="green">Green</option>
  <option value="blue">Blue</option>
</Field>
                            <Field name="consent" label="You must accept the  and Privacy Policy"  type="checkbox" className={'form-control' + (errors.consent && touched.consent ? ' is-invalid' : '')} />
                            <ErrorMessage name="consent" component="div" className="invalid-feedback" />
                        </div>


                        <div className="form-group">
                            <Button variant="outline-primary" type="submit" style={style3}>Register</Button>
                        </div>
                    </Form>
                )}
            />
        )
    }
}

export default Basic; 
//渲染属性
从“React”导入React;
从'react router dom'导入{Link};
从'Formik'导入{Formik,Form,Field,ErrorMessage};
从“react bootstrap”导入{Badge、Button、Col、Feedback、FormControl、FormGroup、FormLabel、InputGroup};
从“是”以是的形式导入*;
常量style1={
宽度:“60%”,
保证金:“自动”
}
常量style2={
paddingTop:'2em',
}
常量style3={
marginRight:“凌晨2点”
}
类Basic扩展了React.Component{
render(){
返回(
{
警报('SUCCESS!!:-)\n\n'+JSON.stringify(字段,null,4))
}}
render={({错误,状态,触摸})=>(
开始
名字
姓
电子邮件
哪个角色最适合你?
密码
确认密码
红色
绿色
蓝色
登记
)}
/>
)
}
}
导出默认基本值;
当我尝试将react引导表单组添加到render方法内部时,例如:

  <Form.Group controlId="formBasicEmail">
    <Form.Label>Email address</Form.Label>
    <Form.Control type="email" placeholder="Enter email" />
    <Form.Text className="text-muted">
      We'll never share your email with anyone else.
    </Form.Text>
  </Form.Group>

电子邮件地址
我们永远不会与其他人共享您的电子邮件。
我得到一个错误,上面写着:

元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入

检查
Formik
的渲染方法

我认为这个错误消息指的是元素类型,意思是“email”-但这没有任何意义,因为我使用的formik表单中已经有一个“email”类型,当我不尝试使用react引导时没有错误


有人知道如何让Formik使用react引导吗?

您使用了错误的
表单。从
react bootstrap
导入它,而不是从
formik
导入,它应该可以工作