问题
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