最近,我设置了相关域并添加了密码自动填充,但我现在想知道如何自动填充它们的名字和姓氏,如下面的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)发布于 2022-04-13 05:59:18
对于TextField,您可以使用.textContentType(_:)修饰符。
UITextContentType结构中的一种内容类型,用于标识文本输入区域的预期语义。其中包括对电子邮件地址、位置名称、URL和电话号码的支持,仅举几个例子。
示例:
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)https://stackoverflow.com/questions/71849554
复制相似问题