Fixing GET forms

5 views
Skip to first unread message

Hernán Morales Durand

unread,
Jul 5, 2016, 3:42:41 AM7/5/16
to il...@googlegroups.com
Hello guys,

I've noticed you cannot have working forms with GET method with current iliadJs. The problem is in the current version a parameter "post" is hardcoded when calling evaluateAction() and "get" is set only when processing anchors, i.e. evaluateAnchorAction().

As a consequence is not easy to implement forms with GET buttons for example.

The current fix I found is retrieving the user specified form type:

    function evaluateFormAction(form) {
        var actionUrl = getFormActionUrl(form);
        var data = jQuery(form).serialize();
        var method = jQuery(form).attr("method");
        evaluateAction(actionUrl, method, data);
    }

Instead of the hardcoded "post"

    function evaluateFormAction(form) {
        var actionUrl = getFormActionUrl(form);
        var data = jQuery(form).serialize();
        evaluateAction(actionUrl, "post", data);
    }

This fix can solve problems with sending attachments from server-side. But is incomplete, because some strange logic using ILUrlBuilder actionKey when retrieving an ILRequest actions... this is, if no _action is found, then actionField gets nil and then callbacks are not processed.

So, _action is set only to anchors, not to forms. So the challenge could be to have something like:

    function hasActionUrl(anchor) {
        if(anchor && jQuery(anchor).attr(''href'')) {
            return (/_action?=(.*)$/).test(jQuery(anchor).attr(''href''));
        }
    }

in

    function getFormActionUrl(form) {
        return jQuery(form).attr(''action'');
    }

Thinking out loud if we prepend "_action" in getForActionUrl() response that would have undesired collateral consequences?

Cheers,

Hernán

Reply all
Reply to author
Forward
0 new messages