Currently, I am working on a project using Angular Material where I need to enforce a required radio group. This means that the user must select a radio button before being able to submit the form. The form should be considered invalid if no radio button is selected.
Below is the code snippet:
<form id="pipelineForm" name="pipelineForm" ng-submit="processForm()" flex layout="column" novalidate>
<md-radio-group ng-model="parameters.selected" ng-required="true" name="analyzerRG"
<md-radio-button ng-value="choiceObj" ng-repeat="choiceObj in parameters.choices" ng-required>
{{choiceObj.text}}
</md-radio-button>
</md-radio-group>
</form>
I have attempted various methods such as making individual <md-radio-button>
required, assigning a name
to the radio group, and using ng-messages
for the required
validation, but without success. Even when inspecting the md-radio-group
in Chrome DevTools, it always shows as
class="ng-valid ng-valid-required"
.
While I could manually check the parameters.selected
property to validate the form, I would prefer if the correct classes were applied to the md-radio-group
so that the form is automatically marked as invalid.
P.S.: I noticed a similar issue on the Angular Material Github page, but it appears to be closed now and the suggested solutions do not work for my scenario.