【问题标题】:Why aren't inputs inside custom elements submitted with the form? [duplicate]为什么在表单提交的自定义元素中没有输入? [复制]
【发布时间】:2019-06-20 06:20:34
【问题描述】:

我在玩 LitElement,尝试制作一些简单的自定义元素。

这是我的 app.js:

class MyInput extends LitElement {
    static get properties() {
        return {
            name: { type: String, reflect: true },
            innerVal: { type: String }
        }
    }

    constructor() {
        super()
        this.innerVal = ''
    }

    render() {
        return html`
          <input type="text" @keyup=${this.inputHandle.bind(this)} />
          <input type="hidden" name="${this.name}" .value="${this.innerVal}" />
        `
    }

    inputHandle(ev) {
        let { target } = ev
        this.innerVal = target.value + '__'
    }
}

customElements.define('my-input', MyInput)

这是我制作的表格:

    <form action="/action" method="POST">
        <div><my-input name="some_name"></my-input></div>
        <div><input name="just_input" /></div>
        <button type="submit">Submit</button>
    </form>

但是,当我按下“提交”时,只会发送来自just_input 输入的数据,而不是来自我的自定义输入的数据:

为什么我的自定义输入值没有提交?

【问题讨论】:

    标签: html forms custom-element lit-element


    【解决方案1】:

    正如有人在 Mastodon 上向我指出的那样,到目前为止,它还没有实现。 Relevant Github issue

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-29
      • 2017-02-20
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      • 2014-04-13
      • 2016-04-04
      • 2014-06-11
      相关资源
      最近更新 更多