最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Magento form validation only works on the last checkbox in a group - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited May 28, 2014 at 13:28 Zabs asked May 28, 2014 at 13:10 ZabsZabs 14.2k51 gold badges179 silver badges311 bronze badges 6
  • Does this post help?? – eyoung100 Commented May 28, 2014 at 13:24
  • thanks but still no joy :( – Zabs Commented May 28, 2014 at 13:26
  • try adding: class="radio validate-one-required organisation_type" to all 3 – eyoung100 Commented May 28, 2014 at 13:29
  • try validate-one-required-by-namefor all radio buttons – MeenakshiSundaram R Commented May 28, 2014 at 13:30
  • neither of them work.. this is really bizarre.. i hate Magento sometimes – Zabs Commented May 28, 2014 at 13:33
 |  Show 1 more ment

2 Answers 2

Reset to default 6

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

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

发布评论

评论列表(0)

  1. 暂无评论