Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (30 sloc) 1.18 KB
class Backtastic.Views.FormView extends Backtastic.View
constructor: ->
@fieldViews = {}
clearErrors: ->
fieldView.clearErrors() for field, fieldView of @fieldViews
displayErrors: (response)->
errors = JSON.parse(response.responseText)
errors = errors.errors if errors.errors #rails does it this way
for field, errorMessages of errors
fieldView: (fieldViewClass, options) ->
fieldView = new fieldViewClass _.extend options,
parentView: @
model: @model
@fieldViews[options.field] = fieldView
dateField: (options) ->
@fieldView(Backtastic.Views.DateFieldView, options)
textField: (options) ->
@fieldView(Backtastic.Views.TextFieldView, options)
selectField: (options) ->
@fieldView(Backtastic.Views.SelectFieldView, options)
save: (event)->
@$("input[type='submit']").attr("disabled", "disabled")
@model.on "error", (model, response) => @displayErrors(response) @$("form").serializeObject()
Something went wrong with that request. Please try again.