Magento form validation only works on the last checkbox in a group

孤街醉人 提交于 2019-12-11 02:24:13

问题


I am using the built-in Magento form validation to ensure the user makes a selection on a particular group of radio boxes.

The code below looks fine however

<div class="input-box">
  <li class="control">
   <input type="radio" class="radio organisation_type" value="1" id="billing:organisation_type_1" name="billing[organisation_type]"> <?php echo $this->__('School') ?></li>
  <li class="control">
   <input type="radio" class="radio organisation_type" value="2" id="billing:organisation_type_2" name="billing[organisation_type]"> <?php echo $this->__('Parent') ?></li>
  <li class="control">
   <input type="radio" class="radio validate-one-required organisation_type" value="3" id="billing:organisation_type_3" name="billing[organisation_type]"> <?php echo $this->__('Business') ?></li>
</div>

I am using the validate-one method on the class on the last radio box

For some reason the code above will only let me proceed if I select the last radio box?? Can anyone explain why if I check either the first or second box the validation is still failing?


回答1:


You need to add validate-one-required-by-name to the last radio button.

<input type='radio' class="validate-one-required-by-name .. "

Take a look at Payment Method when placing an admin order




回答2:


You can't use the same ID in any case. Make your input id attributes always different.



来源:https://stackoverflow.com/questions/23912566/magento-form-validation-only-works-on-the-last-checkbox-in-a-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!