0

After invalidate the default behaviour of the form I would like to display HTML5 client-side validation error bubbles.

I did try the following code but it does not work.

Any ideas?

validateForm: function (event) {
    event.preventDefault();
    // some code
    console.log(this.$el.find('form')[0]); // it display the form I would like to validate
    this.$el.find('form')[0].checkValidity();
});
Rob
  • 4,927
  • 12
  • 49
  • 54
Lorraine Bernard
  • 13,000
  • 23
  • 82
  • 134

1 Answers1

2

Your code about validateForm can be improved in this way:

validateForm: function (event) {
    event.preventDefault();
    // some code
    event.currentTarget.checkValidity();
});

If it does not work the issue will be about how you call validateForm function.

If you are in a Backbone.View, as I suppose since you are using "this.$el", you should write the events object simply in this way:

events: {
    'submit form': 'validateForm'
    // 'click button': 'validateForm' // this way does not work
}
antonjs
  • 14,060
  • 14
  • 65
  • 91