Want to see the full-length video right now for free?
In our Note Backbone model we need to add a validate
method
In the ShowNote Backbone view add an initialize
method
In the initialize method call the listenTo
method to respond to the
invalid
event
initialize: -> @listenTo(@model, 'invalid', @addError)
Add a new method called addError
to handle this event
in the addError
method add a class called error
to the note div
addError: => @$el.addClass('error')
Modify the beginEditing
method to remove the error
class from the note div if it's present
beginEditing: -> @$el.addClass('editing') @$el.removeClass('error')
Open the notes.css.scss file
define an error class under note
&.error { border-color: red; }
invalid
event is not triggeredNote
view we bind to the error
event instead of invalid
Backbone behaves the same as it did for client side validationsNow we add the validation method back to the Backbone model
initialize: ->
@listenTo(@model, 'invalid', @addError)
@listenTo(@model, 'error', @addError)
Commit!