Skip to content

Instantly share code, notes, and snippets.

@besimhu
Forked from leolll/your.html
Created January 27, 2022 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save besimhu/9f2555df1110478fd2211f8880f10394 to your computer and use it in GitHub Desktop.
Save besimhu/9f2555df1110478fd2211f8880f10394 to your computer and use it in GitHub Desktop.
Radio button validation + iodine.js
<label for="password">Plan</label>
<input name="plan" type="radio" id="pro" value="pro" x-bind:class="{'invalid':plan.errorMessage}" data-rules='["requiredChoice:plan"]' data-server-errors='[]'>
<input name="plan" type="radio" id="basic" value="basic" x-bind:class="{'invalid':plan.errorMessage}" data-rules='["requiredChoice:plan"]' data-server-errors='[]'>
<p class="error-message" x-show.transition.in="plan.errorMessage" x-text="plan.errorMessage"></p>
Iodine.addRule("requiredChoice", (value, name) => {
return document.querySelector('input[name="' + name + '"]:checked') != null;
});
Iodine.messages.requiredChoice = "Please select one of these options";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment