Opened 7 years ago

Closed 7 years ago

#16890 closed defect (invalid)

[regression] Support the "form" attribute in dojo/request/xhr

Reported by: ractive Owned by: ractive
Priority: undecided Milestone: 1.10
Component: IO Version: 1.8.3
Keywords: Cc:
Blocked By: Blocking:

Description

dojo/request/xhr does not support the "form" attribute that has been previously supported in dojo/_base/xhr any more.

Migrating from previous versions using on this attribute is quite cumbersome, because the url has to be manually extracted from the form's action attribute and passed as the first param to the xhr.post() method and the form data has to be manually converted to an object to be set as the data attribute.

Posting a form with ajax now got much more complicated than it has been before.

Maybe a new method xhr.postForm(formId, options) could be an alternative because all other methods require an url as the first parameter now.

Change History (4)

comment:1 Changed 7 years ago by bill

Milestone: tbd1.9
Summary: Support the "form" attribute in dojo/request/xhr[regression] Support the "form" attribute in dojo/request/xhr

Sounds like a regression? If so we should address for 1.9.

comment:2 Changed 7 years ago by ractive

Maybe the form attribute has just been "forgotten". There are no traces at all in the source code nor in the documentation so it may have been left out on purpose.

comment:3 Changed 7 years ago by dylan

Milestone: 1.91.10
Owner: changed from Bryan Forbes to ractive
Status: newpending

So, to be clear, you're saying that the following is too difficult:

require(["dojo/dom", "dojo/on", "dojo/request", "dojo/dom-form"],
    function(dom, on, request, domForm){
 
        var form = dom.byId('formNode');
 
        // Attach the onsubmit event handler of the form
        on(form, "submit", function(evt){
            evt.stopPropagation();
            evt.preventDefault();
            request.post(form.target, {
                data: domForm.toObject("formNode"),
            }).then(function(response){
                // ...
            });
        });
    }
);

and you would prefer something like the following which does not currently exist:

require(["dojo/dom", "dojo/on", "dojo/request/postForm"],
    function(dom, on, postForm){
        var form = dom.byId('formNode');
        on(form, "submit", function(evt){
            evt.stopPropagation();
            evt.preventDefault();
            postForm(form, {
            }).then(function(response){
                // ...
            });
        });
    }
);

I think for the simple cases I can see the point, but for more complex cases, sometimes being more explicit about what you're doing makes the API less error prone.

Please let me know if I'm understanding your feedback correctly.

I don't think we'll get this change into 1.9, but we'll keep it open for consideration.

comment:4 Changed 7 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.