V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
594mantou
V2EX  ›  前端开发

快速创建一个表单

  •  
  •   594mantou ·
    mantou132 · 97 天前 · 511 次点击
    这是一个创建于 97 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近优化 DuoyunUI 时写了一些“模式”,就是一些我经常遇到的需求进行了一些抽象实现,比如创建一个表单(复制到控制台试试):

    import("https://esm.sh/duoyun-ui/patterns/form?bundle").then(({ createForm }) => {
      createForm({
        type: "modal",
        data: { firstName: "First Name", lastName: "Last Name", github: "https://github.com/mantou132" },
        header: `Create User`,
        formItems: [
          [{
            type: "text",
            field: "firstName",
            label: "First Name",
          },{
            type: "text",
            field: "lastName",
            label: "Last Name",
          }],{
            type: "text",
            field: "github",
            label: "Github",
          }
        ],
      });
    });
    
    

    返回一个 Promise ,对应提交和取消,参数可以添加 prepareOk/prepareClose 来打断关闭表单。

    字段支持的 type: text password date date-time date-range number checkbox checkbox-group picker radio-group select textarea slot

    其中 slot 是用来自定义的,比如:

    {
      type: "slot",
      slot: new HTMLInputElement(),
      field: "github",
      label: "Github",
    }
    

    模式可以直接创建一个 CRUD 应用: https://duoyun-ui.gemjs.org/zh/blog/crud

    第 1 条附言  ·  97 天前
    忘记了,`HTMLInputElement` 是不可构造的,可以构造自定义函数比如: `new DuoyunColorPickerElement`
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   883 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:42 · PVG 03:42 · LAX 12:42 · JFK 15:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.