0

I have grid in my custom tab.

Need to validate my checkboxes, atlease select one checkbox before submitting the form.

Please have a look at attached screenshot.

enter image description here

help me in this. Thank you!

2 Answers 2

1

I have add common hidden input field to the whole Grid checkbox column, that is below :

<input type="hidden" id="checkBoxesStatus" class="input required-entry" value="" />

and add the below script for checkboxes validation :

<script type="text/javascript">
//<![CDATA[
var validateCheckBoxes = (function() {
var checkBoxesStatus = false;
$$('#adminformsGrid tbody tr .checkbox').each(function(e) {
    if(e.checked) {
        checkBoxesStatus = true;
    }
});
if(checkBoxesStatus) {
    $('checkBoxesStatus').value = 1;
} else {
    $('checkBoxesStatus').value = '';
}
});

$$('#adminformsGrid tbody tr .checkbox').invoke('observe','click', function() {
validateCheckBoxes();
});
$$('#adminformsGrid thead tr .sp-pointer').invoke('observe','click', function() {
validateCheckBoxes();
});

It will work...

0

You can try validate-one-required class.

validate-one-required tends for > At least one textbox/radio element must be selected in a group

To use the validate-one-required validator you must first add the class name to only one checkbox/radio button in the group (last one is probably best) and then place all the input elements within a parent element, for example a div element. That way the library can find all the checkboxes/radio buttons to check and place the validation advice element at the bottom of the parent element to make it appear after the group of checkboxes/radio buttons.

So you can use it like:

<fieldset>
    <input class="checkbox" type="checkbox" name="checkbox[]" />
    <input class="checkbox" type="checkbox" name="checkbox[]" />
    <input class="checkbox" type="checkbox" name="checkbox[]" />
    <input class="checkbox" type="checkbox" name="checkbox[]" />
    <input class="checkbox validate-one-required" type="checkbox" name="checkbox[]" />
</fieldset>

For more check here : Easy Validation by Prototype

1
  • 1
    i want this in grid column..is there any possibilities to do in $this->addColimn() Commented Jun 21, 2016 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.