A quick study of materialize.css shows that in this frame style there is no proper selector for input like radio , check this image:

The following code styling selectors :after for labels. However, adding a selector for the radio inputs does not seem to fix the issue for me.
To fix the problem, you can:
- Make a validator validation function that checks the value of the radio signal and warns the user, then binds this function to an
onsubmit form onsubmit . - Attach the validator function to the submit button, which artificially prevents the button from clicking and submitting the form.
Here's a more understandable approach.
I assume that the developers of this structure deliberately excluded the code for checking the radio block. The radio button is a common user interface element that is part of the radio button group. The "Radio" button is specific, since there can only be one selected value in a group, but must be a selected value .
So, change your M input as follows:
<input class="validate" type="radio" name="mode" value="M" id="m" required="required" data-error="Error msg here">
For this:
<input checked required class="validate" type="radio" name="mode" value="M" id="m">
- HTML5 does not require a value for certain modifiers, such as
required , disabled , selected , so I deleted it. - Removed the unused
data-error attribute. - I moved the modifiers closer to the beginning, so you see them at a glance.
- I added the
checked modifier so that the group of radio stations has a default value.
It seems you are doing a gender selector. There are only two genders, and you always have a gender; there is no reason not to have a default value. In terms of UI / UX design, the switch group should always have a checked item. If you want, you can enable the third option if the user does not want to provide this information.
Here is your updated snippet:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/js/materialize.min.js"></script> <form> <div class="row"> <div class="input-field col s6"> <input checked required class="validate" type="radio" name="mode" value="M" id="m"> <label for="m">M</label> </div> <div class="input-field col s6"> <input required class="validate" type="radio" name="mode" value="F" id="f"> <label for="f">F</label> </div> <div class="col s12" style="margin-top:20px"> <button type="submit" class="waves-effect waves-green btn"> Submit </button> </div> </div> </form>
source share