自动填写名字/姓氏
我最近设置了关联的域并添加了密码自动填充,但是我现在想知道如何自动填充它们的名字和姓氏,如在某些网页上所示,例如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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于
TextField
,您可以使用.textContentType(_:)
修饰符。文档
可能的 contentType 列表
示例:
For
TextField
you can use the.textContentType(_:)
modifier.documentation
list of possible contentTypes
Example: