0

the checkbox required field validation in my code doesn't seem to get triggered on submit although the other input fields are validated. Can any of you check out what the hell's wrong in my code?

<div class="field">
    <label class="label" for="custom_second">
        <span><?php  echo __('Item Delivery Options') ?></span>
    </label>
    <div class="control">
        <?php foreach($deliveryOptionList as $key => $deliveryOptionItem): ?>
            <label class="radio-inline">
                <input class="radio validate-one-required-by-name" type="checkbox" name="rahahaha_data[delivery_options][]" value="<?php echo $key; ?>"> <?php echo $deliveryOptionItem; ?>
            </label>&nbsp;&nbsp;&nbsp;
        <?php endforeach; ?>
    </div> 
</div>

This is how the output looks like:

<div class="field">
<label class="label" for="custom_second">
    <span>Item Delivery Options</span>
</label>
<div class="control">
    <label class="radio-inline">
    <input class="radio validate-one-required-by-name" type="checkbox" name="rahahaha_data[delivery_options][]" value="1"> Rahahaha - online payment</label>&nbsp;&nbsp;&nbsp;
    <label class="radio-inline">
    <input class="radio validate-one-required-by-name" type="checkbox" name="rahahaha_data[delivery_options][]" value="2"> Rahahaha - cash on delivery</label>&nbsp;&nbsp;&nbsp;
    <label class="radio-inline">
    <input class="radio validate-one-required-by-name" type="checkbox" name="rahahaha_data[delivery_options][]" value="4"> Sellers delivery</label>&nbsp;&nbsp;&nbsp;
    <label class="radio-inline">
    <input class="radio validate-one-required-by-name" type="checkbox" name="rahahaha_data[delivery_options][]" value="5"> Buyers pick-up</label>&nbsp;&nbsp;&nbsp;
</div> 

Thanks guys

  • This are the other things I have tested: added the class "checkbox required", using " data-validate", changing the name to regular array : delivery_options[] – Rahahaha Apr 13 '16 at 9:04
  • apparently add the class "checkbox required" and clearing the cache seem to have triggered the validation. but... the error message is not showing up. – Rahahaha Apr 13 '16 at 9:26
1

You have to do below code, use class name as checkbox required to validate checkbox,

<div class="field">
    <label class="label" for="custom_second">
        <span><?php  echo __('Item Delivery Options') ?></span>
    </label>
    <div class="control">
        <?php foreach($deliveryOptionList as $key => $deliveryOptionItem): ?>
           <input class="checkbox required" type="checkbox" name="rahahaha_data[delivery_options][]" value="<?php echo $key; ?>">
            <label class="label radio-inline">
                 <?php echo $deliveryOptionItem; ?>
            </label>&nbsp;&nbsp;&nbsp;
        <?php endforeach; ?>
    </div> 
</div>
  • Hi Rakesh thanks for the feedback, but it is still not working. I've updated my post to include the things I have tested that did not work. – Rahahaha Apr 13 '16 at 9:04
  • i have updated my answer plz keep above code. – Rakesh Jesadiya Apr 13 '16 at 9:11
  • ok i tried the change the class again and deleted the cache folder from the var. i can now see a mage-error class being added to the first checkbox. there is no error message though. – Rahahaha Apr 13 '16 at 9:13
  • Have you checked inside inspect element, whether message is display or not? – Rakesh Jesadiya Apr 13 '16 at 9:16
  • 3
    ok i found the error. we need to move the input checkbox outside the label. it should not be inside the label. the message is showing now. – Rahahaha Apr 13 '16 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.