validateRadio
The validateRadio function validates a specified radio input field. It checks if a radio button within a group is selected and returns an ErrorMessageInterface.
Works in: HTML5, React JS
| Parameter | Type | Default | Description |
|---|---|---|---|
radioInputField | HTMLInputElement | string | undefined | The radio input field or its ID to validate. |
customErrorMessage | object | {} | Custom error message to return if validation fails. |
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);See also
Last updated on