1

ajaxformを使用して、同様のフィールドセットに3つのフォームがあります。私が欲しいのは、フォームが更新されたときに、その親フィールドセットのみを更新することです。$(this) 変数がないため、送信されたフォームのみを更新する ajaxform を指定できません。

$(".toggle-form-submit").parents("form").ajaxForm({
  dataType: 'html',
  success: function(html) {
    var myForm = $(this);
    console.log(myForm);
    if(myForm.parents("fieldset").find(".replaceable").length) {
      updateReplaceableAndClearAndCloseFormWithin(myForm.parents("fieldset"), html);
    } else {
      longPanelUpdateReplaceableAndClearAndCloseFormWithin(myForm.parents("fieldset"), html);
    }
    if( $(".test-categories-list").length) {
      initSortableTestCases();
    }
  }
});

どうやら myForm は応答オブジェクトです。私が欲しいのは、現在のフォームのjqueryセレクターで、その親を見つけることができます。ajaxform インスタンス化で変数を設定できないので、どこに $(this)/myForm を設定すればよいですか?

4

1 に答える 1

3

この jQuery Ajax フォーム プラグインを使用していると仮定すると、success メソッドの 4 番目の引数は、処理された jQuery でラップされたフォームになります。

http://jquery.malsup.com/form/#options-object

したがって、これは機能するはずです:

$(".toggle-form-submit").parents("form").ajaxForm({
  dataType: 'html',
  success: function(html, status, xhr, myForm) {    
  console.log(myForm);
  if(myForm.parents("fieldset").find(".replaceable").length) {
    updateReplaceableAndClearAndCloseFormWithin(myForm.parents("fieldset"), html);
  } else {
    longPanelUpdateReplaceableAndClearAndCloseFormWithin(myForm.parents("fieldset"),     html);
  }
  if( $(".test-categories-list").length) {
    initSortableTestCases();
  }
 }
});
于 2011-03-21T07:46:52.117 に答える