Hi all!
A straight forward thing.
I though it was possible to give a "required" validation to the field radio buttons.
It looks not..
How to do that?
Here's what I did, simply copy pasting...
..but it looks I have to click submit double to allow the check.
I have three radio button, all required (I list them as different items in the form)
If I click the first without being thicked, the validation launch the message.
Item 2 andd 3 are still false, I clicked submit, and I have to do it twice in order to get the 2 validatated, and the same for item 3...
Maybe beacause of the loop?
I've tried this:
but didn't work out...
sorry I am dull in JS..!
A straight forward thing.
I though it was possible to give a "required" validation to the field radio buttons.
It looks not..
How to do that?
Here's what I did, simply copy pasting...
['required-legal', 'You must accept bla bla.',function (v,elm) {
var p = elm.parentNode;
var options = p.getElementsByTagName('INPUT');
for(i=0; i<options.length; i++){
if(options[i].checked == true) {
return true;
}
}
}],
..but it looks I have to click submit double to allow the check.
I have three radio button, all required (I list them as different items in the form)
If I click the first without being thicked, the validation launch the message.
Item 2 andd 3 are still false, I clicked submit, and I have to do it twice in order to get the 2 validatated, and the same for item 3...
Maybe beacause of the loop?
I've tried this:
['required-legal', 'You must accept bla bla.',function (v,elm) {
var p = elm.parentNode;
var options = p.getElementsByTagName('INPUT');
if (options.checked == true) {
return true;
}
}],
but didn't work out...
sorry I am dull in JS..!
Hi gg4j,
Try this - if I've got it right it should check that all the inputs are checked.
Bob
Try this - if I've got it right it should check that all the inputs are checked.
['required-legal', 'You must accept bla bla.',function (v,elm) {
var p = elm.parentNode;
var options = p.getElementsByTagName('INPUT');
var all_checked = true;
for(i=0; i<options.length; i++){
if(options[i].checked == false) {
var all_checked = false;
}
if ( all_checked ) return true;
}
}]
NB not tested and may need debugging.Bob
Thanks but no, it still works the same.
3 separated check buttons (three labels) with the new property required-legal.
Each of them must be required.
With this code, I have the same result of my changes:
test submit for the first not thicked, it does correctly the validation, (I thick the first then)
test submit for the second, the button submit is in click status but not submitting, then clik again and it does the validation (I thick the second one then)
test submit for the third, the button submit is in click status but not submitting, then clik again and it does the validation
It looks like it hold one submit for validate the other two..
For legal agreement is ok, generally people knows they must accept.
But what for a list of required check buttons in a form?
I think for that should be corrected..
3 separated check buttons (three labels) with the new property required-legal.
Each of them must be required.
With this code, I have the same result of my changes:
test submit for the first not thicked, it does correctly the validation, (I thick the first then)
test submit for the second, the button submit is in click status but not submitting, then clik again and it does the validation (I thick the second one then)
test submit for the third, the button submit is in click status but not submitting, then clik again and it does the validation
It looks like it hold one submit for validate the other two..
For legal agreement is ok, generally people knows they must accept.
But what for a list of required check buttons in a form?
I think for that should be corrected..
To make it easy, how to add a functionality required field for the check button field, working as for the other input fields?
Hi gg4,
I think I was making it too complicated. Try this code
Bob
I think I was making it too complicated. Try this code
['required-legal', 'You must accept bla bla.', function (v,elm) {
if ( elm.checked ) return true;
}]
Bob
This topic is locked and no more replies can be posted.