Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTML5 field validation

 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm playing with the built in field validation for HTML5, how can we extend or hook up custom validation to the fields?

I haven't found how to do it yet, so end up not using it and using custom validation with jquery & bootstrap to maintain consistent way of displaying validation message.
 
Rob Crowther
author
Ranch Hand
Posts: 297
5
Android Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Listen to the invalid event and then use setCustomValidity to display a custom message with the browser UI, or display your own custom warning message:
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry if my original question is not clear, what I meant is how can we extend the validation by providing our own rules. Not on creating custom error message. To be specific, is there a standard way to do it rather then writing custom javascript that is not consistent with how HTML5 field validation works.

I'm not a web expert, if I understand the example correctly the callback only get calls once it failed the validation process which raise the invalid event.
 
Rob Crowther
author
Ranch Hand
Posts: 297
5
Android Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wirianto Djunaidi wrote:what I meant is how can we extend the validation by providing our own rules


OK, why don't you give some examples of the sort of rules you have in mind?

Wirianto Djunaidi wrote:if I understand the example correctly the callback only get calls once it failed the validation process which raise the invalid event.


The invalid event will be raised as part of the form submission process, or you can trigger it from a script with the checkValidity() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic