选中/取消选中未在AMP上正确更新的无线电输入字段 [英] Check / uncheck radio input field not updated properly on AMP
问题描述
我已经开发了一个AMP网站,其中有三个单选按钮.
I have developed an AMP site where I have three radio buttons.
- 显示全部
- 仅显示收藏夹
- 清除所有
当我单击清除所有按钮时,它将显示一个灯箱.在那个灯箱上,我有两个按钮.
when i will click on clear all button it will show a lightbox. On that lightbox I have two buttons.
- 好的
- 取消
当用户单击灯箱中的取消"时,将选中显示所有单选输入".我已经用amp状态变量更改实现了它.当我第一次单击取消时,它在显示所有广播输入中正确检查,但是在此之后,如果我单击清除广播输入,然后再次单击取消按钮,则它不会再次显示所有广播输入.
when user click on cancel from the lightbox the show all radio input will be checked. I have implemented it with amp-state variable change. For the very first time when i click on cancel it checked properly in show all radio input but after that if I have click on clear radio input and then cancel button again it does not checked again show all radio input.
在这里我在Codepen中添加了示例代码
Here i have added a sample code in codepen
示例代码链接: https://codepen.io/sayalok/pen/VdEagq
<!DOCTYPE html>
<html amp lang="en">
<head>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<title>Favourites </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,initial-scale=1">
<link rel="manifest" href="/manifest.json">
<link rel="canonical" href="https://ampbyexample.com/introduction/hello_world/">
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
<script async custom-element="amp-lightbox" src="https://cdn.ampproject.org/v0/amp-lightbox-0.1.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom="">
amp-lightbox {
background: rgba(0, 0, 0, .75);
}
amp-lightbox .align-content-center {
height: 100%;
}
.fav-lightbox{
background: #fff;
width: 70%;
position: relative;
top: 45%;
left: 0;
right: 0;
margin: 0 auto;
padding:15px;
border-radius: 10px;
padding-bottom: 35px;
}
.fav-lightbox h4{
color: #000;
margin:0;
font-weight: 600;
margin-bottom: 10px;
}
.fav-pop-title{
overflow: auto;
}
.lightbox-btn-grup{
float: right;
}
.lightbox-btn-grup input[type="submit"], .cancel-btn {
background: none;
border: none;
color:#3A98FF;
font-size: 16px;
}
.lightbox-btn-grup .favOkBtn{
font-weight: 700;
}
.cancel-btn{
text-decoration: none;
}
</style>
</head>
<body>
<amp-state id="partnerLogo">
<script type="application/json">
{
"chkRadio" : "show_all"
}
</script>
</amp-state>
<div class="favorite-page-wrapper static-page-margin">
<div class="favorite-content-filter">
<label>
<input name="filter" value="show_all" type="radio" role="button" tabindex="0"
on="change:AMP.setState({partnerLogo:{chkRadio : 'show_all'}})" checked
[checked]="partnerLogo.chkRadio == 'show_all' ? checked : '' ">
show all
</label>
<label>
<input name="filter" value="show_favorite" type="radio" role="button" tabindex="0"
on="change:AMP.setState({partnerLogo:{chkRadio : 'show_all'}})"
[checked]="partnerLogo.chkRadio == 'show_fav' ? checked : '' ">
show only favorites
</label>
<label>
<amp-lightbox id="favorite-lightbox" layout="nodisplay">
<div class="fav-lightbox" role="button" tabindex="0">
<div class="fav-pop-title">
<h4>Are you sure you want to clear entire list?</h4>
</div>
<div class="lightbox-btn-grup">
<input type="submit" value="Cancel" role="button" tabindex="0"
on="tap:favorite-lightbox.close ,AMP.setState({partnerLogo:{chkRadio : 'show_all'}})"/>
<input type="submit" value="OK" role="button" tabindex="0" class="favOkBtn"
on="tap:favorite-lightbox.close">
</div>
</div>
</amp-lightbox>
<input
name="filter" type="radio" role="button"
tabindex="0" on="change:favorite-lightbox"
[checked]="partnerLogo.chkRadio != show_all ? checked : '' "> Clear All
</label>
</div>
</div>
</body>
</html>
有什么建议吗?
推荐答案
好吧,最后,我从amp-team找到了解决此问题的方法.我正在发布该答案,以便如果任何人遇到相同的问题,他们都可以轻松解决它
Well, at last, I found the solution to this problem from amp-team. I am posting that answer so that if anyone faces the same problem they can solve it easily
<div class="favorite-content-filter">
<label>
<input name="filter" value="show_all" type="radio" role="button" tabindex="0"
on="change:AMP.setState({partnerLogo:{chkRadio : 'show_all'}})" checked
[checked]="partnerLogo.chkRadio == 'show_all' ? checked : '' ">
show all
</label>
<label>
<input name="filter" value="show_favorite" type="radio" role="button" tabindex="0"
on="change:AMP.setState({partnerLogo:{chkRadio : 'show_all'}})"
[checked]="partnerLogo.chkRadio == 'show_fav' ? checked : '' ">
show only favorites
</label>
<label>
<amp-lightbox id="favorite-lightbox" layout="nodisplay">
<div class="fav-lightbox" role="button" tabindex="0">
<div class="fav-pop-title">
<h4>Are you sure you want to clear entire list?</h4>
</div>
<div class="lightbox-btn-grup">
<input type="submit" value="Cancel" role="button" tabindex="0"
on="tap:favorite-lightbox.close ,AMP.setState({partnerLogo:{chkRadio : 'show_all'}})"/>
<input type="submit" value="OK" role="button" tabindex="0" class="favOkBtn"
on="tap:favorite-lightbox.close">
</div>
</div>
</amp-lightbox>
<input
name="filter" type="radio" role="button"
tabindex="0" on="change:favorite-lightbox, AMP.setState({partnerLogo:{chkRadio : ''}})"
[checked]="partnerLogo.chkRadio != show_all ? checked : '' "> Clear All
</label>
</div>
当灯箱打开时,我只需要将partnerLogo.chkRadio设置为其他名称.否则,状态将与选定的无线电不同步.
I just need to set the partnerLogo.chkRadio to something else when lightbox opens. Otherwise, the state would be out of sync with selected radio.
这篇关于选中/取消选中未在AMP上正确更新的无线电输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!