React中reduxForm表单编辑

reduxForm中反写数据在输入框中,数据是从别的模块拉取

.关键代码如下

// 编辑应用表单
class EditCode extends React.Component {
  constructor(props) {
    super(props)
  }

  componentDidMount() { 

  }

  // 取消编辑
  handleBack=()=>{
    window.history.go(-1);
  }

  // 确定编辑
  handleFormSubmit=()=>{
    const { handleSubmit } = this.props;
    handleSubmit()
  }

  render() {
    const { handleSubmit, touched, error, pristine, reset, submitting, loading, initAppData } = this.props;
    return (
        <div className="defence-detail" onSubmit={handleSubmit}>
            <div className=‘tc-panel‘>
                <div className=‘tc-panel-bd‘>
                    <div className=‘param-box‘>
                        <div className=‘param-bd‘>
                            <ul className=‘form-list‘>
                                <li>
                                    <div className=‘form-label required‘>
                                        <label htmlFor=‘Name‘>应用名称</label>
                                    </div>
                                    <div className="form-input">
                                        <Field name=‘Name‘ placeholder=‘必填‘ component={inputAppName}/>
                                    </div>
                                </li>
                                <li>
                                    <div className=‘form-label required‘>
                                        <label htmlFor=‘Developer‘>应用开发商</label>
                                    </div>
                                    <div className=‘form-input‘>
                                        <Field name=‘Developer‘ placeholder="必填" component={inputAppDeveloper}/>
                                    </div>
                                </li>
                                <li>
                                    <div className=‘form-label‘>
                                        <label htmlFor=‘Desc‘>应用描述</label>
                                    </div>
                                    <div className=‘form-input‘>
                                        <Field name=‘Desc‘ component={textareaAppDescription}/>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div className=‘tc-panel-ft‘>
                    <Button onClick={()=>this.handleFormSubmit()} loading={loading}> 确认 </Button>
                    <Button className=‘weak‘ onClick={()=>this.handleBack()} disabled={this.props.disabled}> 取消 </Button>
                </div>
            </div>
        </div>
    )
  }
}

EditCode = reduxForm({
    form: ‘editAppForm‘,// 这是你的表单名称
    validate,
    enableReinitialize:true,
    keepDirtyOnReinitialize:true,// 这个值表示重新初始化表单后,不替换已更改的值,可以用clear来测试
})(EditCode)

EditCode = connect(
    state => ({
      initialValues: state.appManage.initAppData, //appManage是你需要拉取数据的模块 你需要填充的数据initAppData
}), )(EditCode) export default EditCode

官网链接https://redux-form.com/6.7.0/examples/initializefromstate/

原文地址:https://www.cnblogs.com/ChineseLiao/p/10153066.html

时间: 2024-08-25 07:51:24

React中reduxForm表单编辑的相关文章

React中的表单应用

React中的表单应用 用户在表单填入的内容,属于用户跟组件的互动,所以不能用this.props读取. var Input = React.createClass({ //初始化组件数据 getInitialState(){ return {value:'hello'}; }, handleChange(event){ this.setState({value:event.target.value}) }, render(){ var value = this.state.value; <di

React中的表单元素

在web应用开发当中,表单还是很重要的元素. 应用表单组件有:文本框(input.textarea).单选按钮和复选框.Select组件. 文本框:文本框的状态改变即文本框中的内容的改变.此时的state应该是inputValue或者是textareaValue.在状态改变时的处理函数应该是 handleInputChange(e){ this.setState({ inputValue:e.target.value }); } 单选按钮和复选框: 1.单选按钮:它的状态state就是radio

jqgrid 实现行编辑,表单编辑的列联动

这个问题的场景相信大家都遇到过,比如有A,B,C三列,B,C列均为下拉框,但是C列的值是由B列的值来决定的,即C列中的值是动态变化的,变化的依据就是B列中你选择的值.本文给出的是一个实用,简易快捷的实现方式.先看图: 本例子实现的如果是常白班,则班别那一列只显示白班,否则的话,那就显示白晚班.可以看成是两列联动. 实现核心代码为: onSelectRow: function (id) { if (id && id !== lastSel) { jQuery("#TblClassT

angularjs中的表单验证

angular对html原生的form做了封装,增加了很多验证功能 1.代码结构 <form name="signup_form" novalidate ng-submit="signupForm()"> <div> <label>用户名</label> <input type="text" placeholder="Name" name="name"

html5中form表单新增属性以及改良的input标签元素的种类

在HTML5中,表单新增了一些属性,input标签也有了更多的type类型,有些实现了js才能实现的特效,但目前有些浏览器不能全部支持.下面是一些h5在表单和input标签上的一些改动. <!DOCTYPE html><html> <head> <title>表单测试</title> <meta charset="utf-8" /> <!-- 在不支持h5的浏览器中,可以用CSS样式进行改写 --> &

Html中的表单

 在讲解今天Html表单之前,还是先看张图片来刺激一下. 源码 <span style="font-size:18px;"><html> <head> <title>超链接演示</title> <!--网页标题--> <body> <h1 align="center">仿百度搜索框</h1> <form action="01.php&quo

Struts2中防止表单重复提交

一.防止表单的重复提交 1.在表单中加入<s:token/>标签 2.在动作类中加入token的拦截器<interceptor-ref name="defaultStack"></interceptor-ref> <interceptor-ref name="token"></interceptor-ref> 3.增加一个名称为invalid.token的结果视图<result name="

Bootstrap历练实例:导航中的表单

Bootstrap历练实例:导航中的表单,它是使用class.navbar-form类,这确保了表单适当的垂直对齐和在较窄的视口中折叠的行为,使用这个对齐方式选项来决定导航栏中的内容放置在哪里. 实例: <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>

在Action中获取表单提交数据

-----------------siwuxie095 在 Action 中获取表单提交数据 1.之前的 Web 阶段是提交表单到 Servlet,在其中使用 Request 对象 的方法获取数据 2.Struts2 是提交表单到 Action,但 Action 没有 Request 对象,不能 直接使用 Request 对象获取数据 「可以间接使用 Request 对象获取数据」 3.Action 获取表单提交数据主要有三种方式: (1)使用 ActionContext 类 (2)使用 Ser