我有一个带有表单的主干视图。当用户提交表单时,可能会出现验证错误,由后端处理。显示错误后,我希望表单再次可用。我以为我应该只做 this.delegateEvents(),但由于某种原因它不起作用......
这是代码:
class App.Views.PlotsCreate extends Backbone.View
template: JST['plots/create']
events:
'submit #new_plot': 'createPlot'
createPlot: (event) ->
event.preventDefault()
@attributes = plot: {name: $('#new_plot_name').val(), docreate: "true", code: code }
@collection.create @attributes,
wait: true
success: (plot) =>
document.body.style.cursor = 'default'
@showProgress(plot)
error: @handleError
)
handleError: (entry, response) =>
if response.status == 422
errors = $.parseJSON(response.responseText).errors
for attribute, messages of errors
$('#new_plot_name').val("#{message}" for message in messages)
<form class="new_plot" name="create_form" id ="new_plot" data-remote="true" enctype="multipart/form-data">
<textarea class="input" id="new_plot_name" name="name" rows="5" maxlength = '140'></textarea>
<input class="blue_button btn_generate" name="commit" type="submit" value="create" id ="plot_subm"/>
</form>
如何使表单再次起作用(即在显示错误后再次提交事件触发)