自动填写名字/姓氏

发布于 2025-01-20 22:00:47 字数 1406 浏览 3 评论 0原文

我最近设置了关联的域并添加了密码自动填充,但是我现在想知道如何自动填充它们的名字和姓氏,如在某些网页上所示,例如HTML中的下面:

<!DOCTYPE html>
<html>
<head>
<script>
function formSubmit() {
    document.forms["myForm"].submit();
}
</script>
</head>
<body>

<h1>The form name attribute</h1>

<form name="myForm" action="/action_page.php" method="get">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname"><br><br>
  <input type="button" onclick="formSubmit()" value="Send form data!">
</form>

<p>Notice that the JavaScript in the head section uses the name of the form to specify which form to submit.</p>

</body>
</html>

如果您在iPhone上并点击上面的文本框,则在某些情况下向您显示您的名字,以便快速自动填充。现在我的问题是,我如何使用Swiftui与上述相同的概念。

这是我到目前为止在Swiftui中的代码:

@State var displaynamefirst = ""


          TextField("First Name",text:self.$displaynamefirst)
            .autocapitalization(.words)
            .padding()
            .background(RoundedRectangle(cornerRadius:6).stroke(Color("Dominant"),lineWidth:2))
            .padding(.top, 0)
            .submitLabel(.done)

I recently setup associated domains and added password autofill, but I am now wondering how I can autofill their first and last name as seen on some webpages such as below in HTML:

<!DOCTYPE html>
<html>
<head>
<script>
function formSubmit() {
    document.forms["myForm"].submit();
}
</script>
</head>
<body>

<h1>The form name attribute</h1>

<form name="myForm" action="/action_page.php" method="get">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname"><br><br>
  <input type="button" onclick="formSubmit()" value="Send form data!">
</form>

<p>Notice that the JavaScript in the head section uses the name of the form to specify which form to submit.</p>

</body>
</html>

If you are on iPhone and tap in the textbox above, it shows you your first name in some cases for a quick autofill. Now my questions is, how can I use swiftUI to produce to same concept as above.

Here is my code in SwiftUI so far:

@State var displaynamefirst = ""


          TextField("First Name",text:self.$displaynamefirst)
            .autocapitalization(.words)
            .padding()
            .background(RoundedRectangle(cornerRadius:6).stroke(Color("Dominant"),lineWidth:2))
            .padding(.top, 0)
            .submitLabel(.done)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吾性傲以野 2025-01-27 22:00:47

对于 TextField,您可以使用 .textContentType(_:) 修饰符。

文档

UITextContentType 结构中可用的内容类型之一,用于标识文本输入区域所需的语义。其中包括对电子邮件地址、位置名称、URL 和电话号码的支持,仅举几例。

可能的 contentType 列表


示例:

TextField("First Name",text:self.$displaynamefirst)
        .autocapitalization(.words)
        .padding()
        .textContentType(.givenName)          
        .background(RoundedRectangle(cornerRadius:6).stroke(Color("Dominant"),lineWidth:2))
        .padding(.top, 0)
        .submitLabel(.done)

For TextField you can use the .textContentType(_:) modifier.

documentation

One of the content types available in the UITextContentType structure that identify the semantic meaning expected for a text-entry area. These include support for email addresses, location names, URLs, and telephone numbers, to name just a few.

list of possible contentTypes


Example:

TextField("First Name",text:self.$displaynamefirst)
        .autocapitalization(.words)
        .padding()
        .textContentType(.givenName)          
        .background(RoundedRectangle(cornerRadius:6).stroke(Color("Dominant"),lineWidth:2))
        .padding(.top, 0)
        .submitLabel(.done)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文