我使用Material UI对话框创建了一个表单列表.在官方 case 中:

<Dialog
          title="Dialog With Custom Width"
          actions={actions}
          modal={true}
          open={this.state.open}
        >
          This dialog spans the entire width of the screen.
</Dialog>

行动是:

   const actions = [
      <FlatButton
        label="Cancel"
        primary={true}
        onTouchTap={this.handleClose}
      />,
      <FlatButton
        label="Submit"
        primary={true}
        onTouchTap={this.handleClose}
      />,
    ];

如何构建表单并让Dialog提交表单数据?

------------------------------------------------更新-----------------------------------------------

还有一个答案:

在对话框操作按钮中添加属性typeform:

const actions = [
      <FlatButton
        label="Cancel"
        primary={true}
        onTouchTap={this.handleClose}
      />,
      <FlatButton
        label="Submit"
        primary={true}
        onTouchTap={this.handleClose}
        type="submit"        //set the buttom type is submit
        form="myform"        //target the form which you want to sent 
      />,
    ];

并在对话框中为窗体指定属性id:

<Dialog
          title="Dialog With Custom Width"
          actions={actions}
          modal={true}
          open={this.state.open}
        >
        // here can put child component and the code still work even the form is in the child component
         <div className="deal_form">
          <form id="myform" onSubmit = {this.handleCreate} >
            <TextField value={this.state.staff_number} />
          </form>
        </div>
</Dialog>

推荐答案

你可以放一个<;表格>;在对话框中,但也必须将{actions}放在窗体中,而不是actions属性中.提交操作按钮上应该有type="Submit"(type="reset"也受支持,如下所示).

jsFiddle:https://jsfiddle.net/14dugwp3/6/

const {
  Dialog,
  TextField,
  FlatButton,
  MuiThemeProvider,
  getMuiTheme,
} = MaterialUI;

class Example extends React.Component {
  constructor(props) {
    super(props);
    this.state = { open: true };
    this.handleClose = this._handleClose.bind(this);
  }

  _handleClose() {
    this.setState({ open: false });
  }

  render() {
    const actions = [
      <FlatButton
        type="reset"
        label="Reset"
        secondary={true}
        style={{ float: 'left' }}
        />,
      <FlatButton
        label="Cancel"
        primary={true}
        onClick={this.handleClose}
        />,
      <FlatButton
        type="submit"
        label="Submit"
        primary={true}
        />,
    ];

    return (
      <Dialog
        title="Dialog With Custom Width"
        modal={true}
        open={this.state.open}
        >
        <form action="/" method="POST" onSubmit={(e) => { e.preventDefault(); alert('Submitted form!'); this.handleClose(); } }>
          This dialog spans the entire width of the screen.
          <TextField name="email" hintText="Email" />
          <TextField name="pwd" type="password" hintText="Password" />
          <div style={{ textAlign: 'right', padding: 8, margin: '24px -24px -24px -24px' }}>
            {actions}
          </div>
        </form>
      </Dialog>
    );
  }
}

const App = () => (
  <MuiThemeProvider muiTheme={getMuiTheme() }>
    <Example />
  </MuiThemeProvider>
);

ReactDOM.render(
  <App />,
  document.getElementById('container')
);

Reactjs相关问答推荐

无法覆盖MUI工具栏上的左右填充,除非使用!重要

在Next.js中实现动态更改的服务器组件

Reaction-路由v6动态路径RegExp

从Microsoft Excel粘贴复制的单元格时,将Excel单元格格式(粗体、下划线、斜体)带入Reaction

如何在Reac.js中通过子组件和props 调用父组件函数?

Redux Store未触发React组件中的重新呈现

react ';S使用状态不设置新状态

获取未捕获的错误:Gatsby生产版本上的最小化react 错误#418

用于获取带有事件处理程序的API的动态路由

Reaction-路由-DOM v6与v5

在 React 中,如何在指向同一组件的路由中拥有未定义数量的多个动态路径段?

React中useAuthenticator的authState在成功登录后仍保持未认证状态 - 需要强制刷新

try 从 React JS 构建此教程游戏但无法继续前进

cypress `cy.now()` Type 'Promise' 没有调用签名

ReactJS:在导航栏中使用 Select inside Link 组件时如何避免重定向?

从一个获取 axios 请求(ReactJS)中删除默认参数

使用 React 中的功能组件更改另一个组件的状态

当父组件重新渲染时做出react ,我失go 了子状态.我错过了什么?

哪个 PrivateRouter 实现更好:高阶组件还是替换?

根据计算 ReactJs 更新输入字段