简体   繁体   English

如何验证Magento中的至少一个复选框?

[英]How to validate at least one checkbox in Magento?

I have a dynamic form with minimum one checkbox as an array. 我有一个动态表单,其中至少有一个复选框作为数组。

<form action="url" method="post" id="whatever">
  <input class="checkbox" type="checkbox" name="item_ids[]" value="101" />
  <input class="checkbox" type="checkbox" name="item_ids[]" value="102" />
  <input class="checkbox validate-one-required" type="checkbox" name="item_ids[]" value="103" />
  <button type="submit">
</form>

<script type="text/javascript">
    //< ![CDATA[
    var customForm = new VarienForm('whatever');
    //]]>
</script>

I tried to use the hint from several forums to add the "validate-one-required" to the last checkbox in the group. 我尝试使用来自多个论坛的提示来将“需要验证的人”添加到组中的最后一个复选框。 But when I try to submit my form and I checked the first checkbox Magento told me that I have to select at least one option. 但是,当我尝试提交表单时,我选中了第一个复选框,Magento告诉我,我必须至少选择一个选项。 Funny! 滑稽! I guess I did it. 我想我做到了。

Is there something else especially in the javascript area I had to add? 特别是在我必须添加的javascript区域中,还有其他内容吗?

尝试将类validate-one-required-by-name附加到您需要验证的所有输入字段中,只要它们具有相同的名称即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM