- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2016
05:45 PM
03-02-2016
05:45 PM
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.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2016
11:00 AM
09-05-2016
11:00 AM
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>
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2016
02:13 AM
03-03-2016
02:13 AM
Re: How to validate radio button?
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>
---
Problem Solved Click Accept as Solution!:Magento Community India Forum
Problem Solved Click Accept as Solution!:Magento Community India Forum
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2016
05:09 AM
03-03-2016
05:09 AM
Re: How to validate radio button?
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?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2016
11:00 AM
09-05-2016
11:00 AM
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>