【问题标题】:Stripe Address Element: how to get the value of the Name field?Stripe Address Element:如何获取Name字段的值?
【发布时间】:2023-02-03 23:17:09
【问题描述】:

address 缺少与名称相关的值,即使 addressElement 正在呈现名称字段,即使使用与 Stripe 文档 here 中提到的相同代码也是如此

addressElement.on('change', (event) => {
  if (event.complete){
    // Extract potentially complete address
    const address = event.value.address;
  }
})

返回这个

{
    "line1": "",
    "line2": null,
    "city": "",
    "country": "US",
    "postal_code": "",
    "state": ""
}

似乎获得价值的解决方法看起来像

document.getElementById('Field-nameInput').value

但看起来并不优雅。

Name字段的值在哪里?我如何得到它?我在这里遗漏了一些明显的东西吗?

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    这在更改事件中可用作 value.name,如果您使用 split 显示名称,则可用作 firstNamelastName。来自value (reference) 的文档:

    包含当前地址信息的对象。 firstNamelastName 属性仅在设置了 display.name 选项时出现 分开。 phone 属性仅在 fields.phone 选项出现时出现 设置为always

    【讨论】:

      猜你喜欢
      • 2022-06-15
      • 2023-03-26
      • 1970-01-01
      • 2020-06-03
      • 1970-01-01
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多