Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ic-push-url not working return #237

Open
mrGrochowski opened this issue Mar 7, 2018 · 5 comments
Open

ic-push-url not working return #237

mrGrochowski opened this issue Mar 7, 2018 · 5 comments

Comments

@mrGrochowski
Copy link

mrGrochowski commented Mar 7, 2018

Related to #77 (comment)
Can You show me example of X-IC-PushURL ? @carsongross
I can't make it work in client-side script only. My backend dev w
on't hear about return special http headers.

For me if some field is sent by GET method it have to appear in url adress like in simple
<a ic-src=''></a> url..

There is code example of my project (new lines only for readability):

<form ic-push-url="true" 
action="index.php" 
ic-get-from="index.php" 
ic-target="#content" 
ic-select-from-response="#content" 
method="GET" 
id="form">
	<input type="hidden" name="co"       value="{{switch}}" />
	<input type="hidden" name="akcja"    value="{{akcja}}" />
	<input type="hidden" name="segment"  value="{{GETsegment}}" />
	<input type="hidden" name="spolka"   value="{{GETspolka}}" />
	<input type="hidden" name="doradca"  value="{{GETdoradca}}" /> 
	<select              name="okres"    id="select-okres">
	    {% for item in arr %}
	        <option value="{{item.id}}" 
		{% if item.id == GETokres %} selected="selected" {% endif %}>
                {{item.nazwa}} 
            </option>
	    {% endfor %}
	</select>
</form>

or

<form ic-push-url="true" 
action="index.php" 
ic-get-from="index.php?co={{switch}}
&akcja={{akcja}}
&segment={{GETsegment}}
&spolka={{GETspolka}}
&doradca={{GETdoradca}}" // as you see I can't put &okres={{GETokres}} field becouse i send double times 
ic-target="#content" 
ic-select-from-response="#content" 
method="GET" 
id="form">
	//<input type="hidden" name="co" value="{{switch}}" />
	//<input type="hidden" name="akcja" value="{{akcja}}" />
	//<input type="hidden" name="segment" value="{{GETsegment}}" />
	//<input type="hidden" name="spolka" value="{{GETspolka}}" />
	//<input type="hidden" name="doradca" value="{{GETdoradca}}" /> 
    <select name="okres" id="select-okres">
	    {% for item in arr %}
	        <option value="{{item.id}}" {% if item.id == GETokres %} selected="selected" {% endif %}>
                {{item.nazwa}} 
            </option>
	    {% endfor %}
	</select>
</form>
@1cg
Copy link
Contributor

1cg commented Mar 15, 2018

Hi There,

If you are using a select for navigation, intercooler isn't going to pick up the parameters with a client-side ic-push-url. Are normal anchors a possibility?

@mrGrochowski
Copy link
Author

mrGrochowski commented Mar 19, 2018

No. This case require select fiters.

Carson I resolve problem with few lines of code. Intercooler is gorgeous tool and maybe You have to consider about checking, is form element includs method==GET and ic-push-url. Then serialize using jQuery method (what You already included ). On last put resault to ic-src and let code work.

above implement pubsub lib
App.IntercoolerHelper = (function () {

    var init = function (params) {
        var _params = params || {
            element: "form",
            events: "select change",
            property: "[ic-push-url][ic-src][method*=get] , [ic-push-url][ic-src][method*=GET] "
        };

        PubSub.publish("/IntercoolerHelper/init", {
            element: $(_params.element),
            events: _params.events,
            property: _params.property
        });

    }

    var _checkAttrib = PubSub.subscribe("/IntercoolerHelper/init", function (params) {
        var _params = params || {
            property: "[*=*]"
        };
        var $fulfillingElems = _params.element.map(function () {
            return $(this).is(_params.property) ? $(this) : "";
        })
        _params.element = $fulfillingElems;

        PubSub.publish("/IntercoolerHelper/thatFormsAvailbe", _params);

    });


    var listener = function (params) {
        var _params = params || {};

        _params.element.each(function () {
            $(this).on(_params.events, function (e) {
                _params.element = $(this);
                PubSub.publish('/IntercoolerHelper/eventOccur', _params);
            });
        })
    }
    
    var _listener = PubSub.subscribe("/IntercoolerHelper/thatFormsAvailbe", listener );

    var _replaceICsrc = PubSub.subscribe("/IntercoolerHelper/eventOccur", function (params) {
        var _params = params || {};

        _params.element.each(function () {
            $(this).attr("ic-src", "" + $(this).attr('action') + "?" + $(this).serialize());
            $(this).attr("ic-get-from", "" + $(this).attr('action') + "?" + $(this).serialize());
        });

    });

    return {
        init: init,
        listener:listener
    }
})();

and


App.instance_IntercoolerHelper = App.IntercoolerHelper;


$(document).ready(function () {

    $("form select").on("select change", function () {
        $(this).parents("form").submit();
    });
    iCRMApp.instance_IntercoolerHelper.init();


    Intercooler.ready(function () {
        iCRMApp.instance_IntercoolerHelper.init();
        
        $("form select").on("select change", function () {
            $(this).parents("form").submit();
        });

    });
});

@1cg
Copy link
Contributor

1cg commented Mar 19, 2018

:) I have always felt this was a shortcoming, but I also don't want to include every variable in the URL when it is a GET. Maybe we should have an additional attribute, something like ic-push-parameters="foo, bar" that you can use to specify the parameters that should be pushed?

What do you think?

@mrGrochowski
Copy link
Author

Thas looks promising but in condition if I can set ic-push-parameters="*"

@mrGrochowski
Copy link
Author

How it's goin ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants