amp-html - 在 amp 中使用只读模式验证输入字段
问题描述
有什么问题?
我的表单上有两个输入字段。我为每个输入创建不同的验证,这就是我使用 custom-validation-reporting="show-first-on-submit" 的原因。我的第一个输入是目的地,第二个输入是日历。当用户提交没有日期的表单时,我想向用户显示我能够完美显示的验证消息。但我的问题是我的第二个/日历输入上的光标指针实际上是我想避免的,因为它是一个日期字段,我不想让用户在日期字段上输入,我想让它只读。
如果我把 readonly 放在那里,我对第二个输入的自定义验证不起作用。
可能的解决方案是什么
我在 codepen https://codepen.io/sayalok/pen/yqXoab上创建场景
我们如何重现这个问题?
如果这是一个功能请求,您可以使用此部分指向一个原型/模型,以帮助我们理解请求。
哪些浏览器受到影响?
所有浏览器
哪个 AMP 版本受到影响?
1531800879103
<div class="home-alert-msg" visible-when-invalid="valueMissing" validation-for="search">
<span>Please enter your destination</span>
</div>
<div class="start_date_err_msg home-alert-msg" visible-when-invalid="valueMissing" validation-for="startDate">
<span>Enter your trip dates.Search Without Date</span>
</div>
<form method="get" action="https://google.com/" target="_top" class="p2 form" id="form" custom-validation-reporting="show-first-on-submit">
<div class="wrapper">
<div class="form-grid">
<div class="form-item city-state">
<input placeholder="Where do you want to stay?" name="search" type="text" id="search" required autocomplete="off"/>
</div>
</div>
</div>
<div>
<input type="text" name="date_start" placeholder="Check In" id="startDate" required on="tap:lb.open">
</div>
<input type="text" name="date_end" placeholder="Check Out" id="endDate" required on="tap:lb.open" readonly>
<amp-lightbox id="lb" layout="nodisplay">
<div class="align-content-center">
<amp-date-picker type="range"
id="drp" on="activate: lb.open;deactivate: lb.close;"
locale="en" format="YYYY-MM-DD"
first-day-of-week="<?= $this->start_day ?>"
mode="static" layout="fixed-height"
height="430" start-input-selector="#startDate"
end-input-selector="#endDate" open-after-clear>
</amp-date-picker>
</div>
</amp-lightbox>
<div>
<input type="submit" class="subscribe-button" id="subscribe-button-id" value="Submit">
</div>
</form>
代码笔网址: https ://codepen.io/sayalok/pen/yqXoab
解决方案
这是一个错误,有一个 GitHub 问题可以解决这个问题。请参阅:https ://github.com/ampproject/amphtml/issues/17687
推荐阅读
- dart - 无法弄清楚如何从列表中分配正确的答案值
在颤振的多项选择测验中, - javascript - 如何自定义设置原型链(构造函数)?
- angular - 在不丢失上下文的情况下处理结构指令上的调整大小事件
- ios - 是否可以将 UIPanGestureRecognizer 子类化以在达到某个距离阈值后出现它的开始状态
- sql-server - 检查多个 SQL Server .bak 备份文件是否来自同一个备份
- php - PHP:如何修复错误无法解析 XML 数据?
- c++ - 这个带有默认参数的 c++ 代码如何编译?
- php - Laravel:为什么 var_dump/dump/dd 会影响 auth()->login() 函数
- api - api 密钥如何安全地存储在移动应用程序中?
- android - 没有注册 Opkernel 来支持 Op 'SparseSoftmaxCrossEntropyWithLogits'