Giter Site home page Giter Site logo

Comments (8)

56600535 avatar 56600535 commented on May 22, 2024

我也有相同的问题,我有两个提交,一个是预览订单,一个是提交订单,需求没法做。

from ant-design-mini.

Alpsli avatar Alpsli commented on May 22, 2024

我们正在重构当前的表单,这个问题我这边临时解决下

from ant-design-mini.

56600535 avatar 56600535 commented on May 22, 2024

我们正在重构当前的表单,这个问题我这边临时解决下

我尝试了一下 onTap会在 htmlType="submit"之前执行,所以我给绑定了一个点击事件设置一个标记,并在submit事件中进行判断,然后执行不同的逻辑,我不确定onTap事件是否总是可以在submit之前执行,但这临时的解决了我的问题。

// buy.js
Page({
  data: {
    // 提交是否是预览订单
    previewOrderFlag: false
  },
  // 表单提交事件
  orderSubmit(e) {
    if(this.data.previewOrderFlag){
      this.previewOrder();
      return;
    }
   // 这里是提交的逻辑
  },
  previewOrder(){
    if(this.data.previewOrderFlag){
      // 预览订单逻辑
      this.setData({
        previewOrderFlag: false
      })
    }else {
      this.setData({
        previewOrderFlag: true
      })
    }
  }
}

from ant-design-mini.

56600535 avatar 56600535 commented on May 22, 2024

我们正在重构当前的表单,这个问题我这边临时解决下

我不是一个专业的前端工程师,您知道onTap和 submit是同步还是异步执行吗?我想知道这样做是否会有问题。

from ant-design-mini.

Alpsli avatar Alpsli commented on May 22, 2024

onTap 是会立刻执行,submit 会触发form的validate校验等,你这样写是ok的,如果你还担心时序问题,你可以给handlesubmit 采用 setTimeout 异步执行

from ant-design-mini.

jc9702507 avatar jc9702507 commented on May 22, 2024

#305

from ant-design-mini.

jc9702507 avatar jc9702507 commented on May 22, 2024

1.0 使用方式:

<form-input
  label="用户名"
  name="account"
  ref="handleForm1"
/>

<form-input
  label="密码"
  name="password"
  password
  ref="handleForm1"
/>

<button onTap="submitForm1">提交表单1</button>

<form-input
  label="用户名"
  name="account"
  ref="handleForm2"
/>

<form-input
  label="密码"
  name="password"
  ref="handleForm1"
/>

<button onTap="submitForm1">提交表单2</button>
import Form from 'antd-mini/es/Form/form';

Page({
  form1: new Form(), // 表单1 
  form2: new Form(), // 表单2
  handleForm1(ref) {
    this.form1.addItem(ref);
  },
  handleForm2(ref) {
    this.form2.addItem(ref);
  },
  async submitForm1() {
    const values = await this.form1.submit();
    console.log(values);
  },
  async submitForm2() {
    const values = await this.form2.submit();
    console.log(values);
  },
});

from ant-design-mini.

jc9702507 avatar jc9702507 commented on May 22, 2024

https://ant-design-mini.antgroup.com/components/form#%E5%A4%9A%E4%B8%AA%E8%A1%A8%E5%8D%95 多个表单示例

from ant-design-mini.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.