validateRadio
Validates a single radio group by its input name.
Returns: string \| boolean \| ErrorMessageInterface
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
radioInputField | `string \ | HTMLInputElement` | required | - |
customErrorMessage | any | optional | - | A custom message to use instead of the default, if the group is invalid. |
Usage
Example: Validate a Radio Button Group
// Using with a radio input element
const radioElement = document.querySelector('input[name="gender"]');
const result = nfsfu234FormValidation.validateRadio(radioElement, {
message: 'Please select a gender.'
});
console.log(result);
// Using with a radio input element ID
const resultById = nfsfu234FormValidation.validateRadio('genderRadioId', {
message: 'Please select a gender.'
});
console.log(resultById);Last updated on