0

I'm trying to find a way how to submit multiple forms with ajax in one xhr.post call with dojo. The documentation at the bottom of this page says:

In fact, the attribute “form:” could be set on each node, not only on form nodes. If your page contains more than one form and these forms are enclosed with a div- or span-tag, then you’re able to submit all these forms, if you set “form:” to the surrounding div- or span-tag.

Specifiying the id of e.g. a div that contains multiple forms as the "form" attribute in an xhr call does not work:

xhr.post({
    form: "idOfDivThatSurroundsManyForms",
    ...
});

It fails in domForm.formToObject, that really expects a form node (or id) which contains an elements attribute.

Is this part of the documentation just wrong or am do I miss something?

Do you have any ideas how to easily combine multiple forms into one xhr call in other ways?

4

1 に答える 1

1

ドキュメントが間違っていて、あなたの観察が正しいと思います。form属性はformToObject引数として送信されます。

回避策は次のとおりです。

require(["dojo/_base/xhr", "dojo/query", "dojo/_base/lang", "dojo/dom-form"], function (xhr, query, lang, domForm) {

  var mergedForms = {}
  query('form', 'idOfDivThatSurroundsManyForms').forEach( function(form) {
        lang.mixin(mergedForms, domForm.formToObject(form));
  } );
  xhr.post( {

    content: mergedForms
  } );

});
于 2012-11-03T20:37:29.713 に答える