Hi, in my custom module, I have a form which has radio buttons.
When I click the submit button it does not validate the radio button.
<?php$question = Mage::getModel('emme_question/question')->getCollection()->getLastItem(); $answers = $question->getSelectedAnswersCollection(); ?> <h4><?php echo $this->escapeHtml($question->getValue()); ?></h4> <ul> <?php foreach ($answers as $answer): ?> <li> <label><?php echo $this->escapeHtml($answer->getValue()) ?></label> <input type="radio" name="my_custom_answer" value="<?php echo $answer->getId() ?>" required> </li> <?php endforeach ?>
Solved! Go to Solution.
I solved
<?php $question = Mage::getModel('emme_question/question')->getCollection()->getLastItem(); $answers = $question->getSelectedAnswersCollection(); ?> <div id="custompaymentmethod-question"> <h4><?php echo $this->escapeHtml($question->getValue()); ?></h4> <ul> <?php foreach ($answers as $answer): ?> <li> <label><?php echo $this->escapeHtml($answer->getValue()) ?></label> <input type="radio" name="my_custom_answer" value="<?php echo $answer->getId() ?>" required> </li> <?php endforeach ?> </div> <script> jQuery(function ($) { $('#co-payment-form').on('change.mm', function () { var is_question_active = ! $('#p_method_custompaymentmethod').is(':checked'); $('#custompaymentmethod-question input').attr('disabled', is_question_active); }) }) </script>
Hi @Benix89
Try with class name validate-one-required-by-name and assign same name to both radio buttons.
sample code :
<ul class="options-list" id="options-1-list"> <li> <input type="radio" value="1" id="options_1" name="myradio1" class="validate-one-required-by-name"> <span class="label"> <label for="options_1">Blue </label> </span> </li> <li> <input type="radio" value="2" id="options_2" name="myradio1" class="validate-one-required-by-name"> <span class="label"> <label for="options_1">Blue </label> </span> </li> </ul>
As advised, I added class name validate-one-required-by-name.
I modified the code
<?php$question = Mage::getModel('emme_question/question')->getCollection()->getLastItem(); $answers = $question->getSelectedAnswersCollection(); ?> <h4><?php echo $this->escapeHtml($question->getValue()); ?></h4> <ul> <?php foreach ($answers as $answer): ?> <li> <label><?php echo $this->escapeHtml($answer->getValue()) ?></label> <input type="radio" name="my_custom_answer" value="<?php echo $answer->getId() ?>" class="validate-one-required-by-name" required> </li> <?php endforeach ?>
Now, however, it does not produce any output
Why?
I solved
<?php $question = Mage::getModel('emme_question/question')->getCollection()->getLastItem(); $answers = $question->getSelectedAnswersCollection(); ?> <div id="custompaymentmethod-question"> <h4><?php echo $this->escapeHtml($question->getValue()); ?></h4> <ul> <?php foreach ($answers as $answer): ?> <li> <label><?php echo $this->escapeHtml($answer->getValue()) ?></label> <input type="radio" name="my_custom_answer" value="<?php echo $answer->getId() ?>" required> </li> <?php endforeach ?> </div> <script> jQuery(function ($) { $('#co-payment-form').on('change.mm', function () { var is_question_active = ! $('#p_method_custompaymentmethod').is(':checked'); $('#custompaymentmethod-question input').attr('disabled', is_question_active); }) }) </script>