Validate control HTML5 before excute method - Song Nghia - Microsoft Dynamics 365 Vietnam

Song Nghia - Microsoft Dynamics 365 Vietnam

Microsoft Dynamics AX/365 Outsourcing Service

Breaking

Wednesday, February 13, 2019

Validate control HTML5 before excute method


Validate control HTML5 before excute method 

* HTML

<form id="form" action="">

  <input type="text" required />
  <input id="submit-hidden" type="submit" style="display: none" />

</form>

<button id="btn-submit">Submit</button>

*Javascript

$("#btn-submit").on("click", function() {
  if (!$("#form")[0].checkValidity()) {
    // If the form is invalid, submit it. The form won't actually submit;
    // this will just cause the browser to display the native HTML5 error messages.
    $("#form").find("#submit-hidden").click();
  }
});


No comments:

Post a Comment