Skip to content

Instantly share code, notes, and snippets.

@Mulli
Last active December 10, 2021 03:53
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 Mulli/7425a153c59bb5ac618a88c3e4afbd6b to your computer and use it in GitHub Desktop.
Save Mulli/7425a153c59bb5ac618a88c3e4afbd6b to your computer and use it in GitHub Desktop.
/* Add the following right after the Form widget as HTML widget */
/* Assume name field with id="name" and email field with id="email" */
<script>
jq2 = jQuery.noConflict();
jq2(function( $ ) {
$(":submit").click(function(event){
let name = $("#form-field-name").val();
let email = $("#form-field-email").val();
// alert('submit clicked name='+name + " email="+email+"<<");
if ((name === undefined || name === "") && $('#name-err').length === 0)
$("#form-field-name").after( "<span style='color:red' aria-label='alert' id='name-err'>Name field is required</span>");
if ((email === undefined || email === "") && $('#email-err').length === 0)
$("#form-field-email").after( "<span style='color:red' aria-label='alert' id='email-err'>Email field is required</span>");
//$("#form-field-email").css({"backgroundColor": "red", "color": "blue"});
//$("#form-field-name").css({"border": "5px solid red"});
//event.preventDefault();
});
$("#form-field-name").change(function() {
$("#name-err").remove();
});
$("#form-field-email").change(function() {
$("#email-err").remove();
});
});
</script>
@Mulli
Copy link
Author

Mulli commented Dec 10, 2021

Notes:

  1. Make sure that form field id values are 'name' and 'email' - You may change as desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment