I have theoretical* solution building off Paulpro's answer above that uses the uniqueness property of Set
to filter a list of element names from JQuery:
var radioNames = new Set(Array.from($('input:radio').map(function() { return this.name } )));
var inputGroupCount = radioNames.length;
if( $('input:radio:checked').length < inputGroupCount){
// At least one group isn't checked
}
This uses the map()
function to extract the name
attributes from the radio groups. This is then converted to an Array
, which is used as the constructor argument for Set
.
Unfortunately, as of April 2016 there is no support for Set(iterable)
and Array.from()
in IE; Opera and Safari have limited support.
If you can ensure your users are on Chrome or Firefox, or this is backend code, then go ahead!