0

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

フォームを再び機能させるにはどうすればよいですか (つまり、エラーが表示された後にイベントを再度送信します)。

4

1 に答える 1

1

検証に失敗しても、通常はイベント バインディングに対して何もしません。実際、技術的には、ビューには検証メソッドさえありません。モデルのみが行います (そのメソッドが行うのは、「エラー」イベントをトリガーして false を返すことだけです)。ビューを壊しているコードが最後にないのは確かですか?

于 2012-11-08T18:55:07.063 に答える