フォーム付きのバックボーン ビューがあります。ユーザーがフォームを送信すると、バックエンドによって処理される検証エラーが発生する可能性があります。エラーを表示した後、フォームを再び使用できるようにします。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>
フォームを再び機能させるにはどうすればよいですか (つまり、エラーが表示された後にイベントを再度送信します)。