Is it possible to pass list parameter from browser to a handler function in Snap?
How do I construct a multiple parameters URL from a list and send it to a handler function?
For instance, I need to delete some table rows or any other objects.
I can not do it with the usual REST route:
("/objects/:id", method DELETE deleteObject)
simply because there could be too many and deleting 100 rows one by one can get a bit tedious.
I chose the doomed objects via checkbox input, say [3,4,6,8] rows need to be deleted.
So how do I pass that list to the handler within URL and what would route look like for the action ?
UPDATE
Well, I finally did it with jquery and ajax call.
Snap's "getParams" function can process multiple parameters URL but I still cannot figure out how to actually construct the URL without jquery and ajax.
I used javascript to collect the items to be deleted and build the array of the items.
I then used ajax to construct multiple parameters URL and send it to the handler.
Few things to note with this method and Snap:
-- Snaps's "getParams" function only supports old style multiple parameters URL:
"a=1&a=2&a=3&a=4"
and not the new one:
"a[]=1&a[]=2&a[]=3&a[]=4"
which makes passing complex parameters impossible.
-- The route should be:
("/objects/", method DELETE deleteObject)
and not the:
("/objects/:ids", method DELETE deleteObject)
I did not answer my question because I don't believe it is the only way to pass multiple parameters URL with snap.
Although "getParams" can process it, my question still stays: how do I construct the URL and send it off to a handler?
For instance, Rails uses "link_to" function within view logic to construct the URL. Snap does not use any logic inside templates so how does it work then?
It just can't be that the only way to pass multiple parameters URL in snap is with the help of javascript...?
Please someone confirm this for me?
You're pretty much there. The following form...
<form action="/foo">
<ul>
<li>Row 1: <input type="checkbox" name="a" value="1"/></li>
<li>Row 2: <input type="checkbox" name="a" value="2"/></li>
<li>Row 3: <input type="checkbox" name="a" value="3"/></li>
<li>Row 4: <input type="checkbox" name="a" value="4"/></li>
<li>Row 5: <input type="checkbox" name="a" value="5"/></li>
</ul>
<input type="submit" name="submit" value="Submit"/>
</form>
...gets submitted like this.
http://localhost:8000/foo?a=2&a=3&a=5&submit=Submit
Then, inside your handler, this will get you a list of ByteStrings.
fooHandler = do
as <- getsRequest (rqParam "a")
So this doesn't require JavaScript at all. But it works with JavaScript as well. If you use jQuery to submit a list like this...
var fieldData = { rows: [0,1,4], cols: [2,3,5] };
$.getJSON('http://localhost:8000/foo', fieldData, ...);
...then you'll have to make an adjustment for the brackets
rs <- getsRequest (rqParam "rows[]")
cs <- getsRequest (rqParam "cols[]")
Related
Every time I run this code, I get an issue reaching to the targeted page. The site requires post request parameter to be filled in to reach the page where I am after. However, using get request it was good to go until it hits "Var4" parameter within my code. Inspecting element I could see that it indicates as hidden. If i left the hidden parameter blank then it redirects to another location. So, satisfying this thing to get to the targeted page is beyond my capability. Any suggestion will be appreciated.
from selenium import webdriver
driver = webdriver.Chrome(r"C:\Users\ar\Desktop\Chromedriver\chromedriver.exe")
driver.get('https://www.infocomm.org/cps/rde/xchg/infocomm/hs.xsl/memberdirectory.htm')
Var1='Professional Services Providers'
Var2='AUSTRALIA'
Var3='0'
Var4='1'
driver.find_element_by_xpath('//select[#name="mas_type"]').send_keys(Var1)
driver.find_element_by_xpath('//select[#name="mas_cntr"]').send_keys(Var2)
driver.find_element_by_xpath('//input[#name="OtherCriteria"]').send_keys(Var3)
driver.find_element_by_xpath('//input[#name="DoMemberSearch"]').send_keys(Var4)
driver.find_element_by_xpath('//input[#type="submit"]').click()
Element for the hidden stuffs which should be applicable for "Var4":
<form name="searchform" id="searchform" action="memberdirectory.htm" method="post" onsubmit="return Checkform();">
<input type="hidden" id="DoMemberSearch" name="DoMemberSearch" value="1">
<div class="login block-type-a block">
As workaround, you can try execute javascript with selenium.
For example, to unhide element
driver.execute_script("document.getElementById('DoMemberSearch').type = 'text';")
or set value directly
driver.execute_script("document.getElementById('DoMemberSearch').value = '%s';" % Var4)
you could not sendkeys to a hidden element, what you can do is to use javascript to send the value
probably something like this
driver.execute_script("document.getElementById('DoMemberSearch').value='1')
My SharePoint input tag is using an XSLT variable for the redirect. I would like to substitute it for a javascript function to determine the value of the users input. Is this possible from within this tag? If not is possible to run a javascript function from within as XSLT variable? The following article show that something like this is possible but I need an example. http://www.nothingbutsharepoint.com/2011/05/05/extending-the-dvwp-passing-xsl-variables-to-javascript-aspx/
Thank you in advance.
<input type="button" id="Submit" value=" Submit " style="width:100px" onclick="javascript: if(!PreSaveItem()) return false;{ddwrt:GenFireServerEvent(concat('__commit;__redirect={',$RedirectLoc,'}'))}"/>
Basically behind GenFireServerEvent is a __doPostBack function.
__doPostBack('elementgeneratedname','__redirect={' + value '}');
Take a look into the browser what code is generated and use it in your function. Most probably first argument is not the id of the button and is the name of the web part container (somthing like 'ctl00$PlaceHolderMain$WebPartId').
This question already has answers here:
What happens if the action field in a <form> has parameters?
(4 answers)
Closed 7 years ago.
I'm writing an application that, unfortunately, still has IE9 support. my requirement has another application posting data and redirecting (via a form POST) into my application, along with query parameters. I'm using Node and express to parse the query params and render a page. I'm running into an issue where, if there are query parameters on a post request, IE9 is actually making three requests, one POST with data, one GET with query params, and one GET without anything attached at all. This seems to effect only IE9, any suggestions on how to make it happen like all other browsers, in one request?
EDIT: now with code
<form action="/testPath/?path=placetoGo&group-id=281740360804&ref-id=2817403600034&itineraryTypeCode=RT&type=edd&num-adults=1" method="POST">
<input type="hidden" name="data" value='something'>
<input type="submit" value="Submit">
</form>
so that's the request to the node/express server.
on the server, IE9 comes in with three requests, first one is a POST with the object on the body. the second is a GET with the query params, and the third is a GET without the post data or query params.
Did You try to change the type attribute of the submit button from submit to button since you post with javascript
also change
<form action="/testPath/?path=placetoGo&group-id=281740360804&ref-id=2817403600034&itineraryTypeCode=RT&type=edd&num-adults=1" method="POST">
to
<form action="/testPath/placetoGo&281740360804&2817403600034&RT&edd&1" method="POST">
I have a node.js that consumes mongodb data and outputs lists using knockout.js
When i invoke the view i pass a json structure using
res.render('list', { items:json });
In the list.ejs template page i've defined a hidden element:
<input type="hidden" id="hidden" value="<%= items %>">
and in .js file i read its value:
var json=$("#hidden").val();
var tkts=jQuery.parseJSON(json);
var vm=new AppViewModel(tkts);
Well...it runs but i think (hope) there must be a better way do it ... is there a way to avoid a hidden html var, for example?
Currently I can think of three ways to do this.
1.) Assign the data to a variable in your JavaScript code:
<script type="text/javascript">solution1 = {"name": "solution1"}</script>
solution1
2.) Add a data-attribute to an element of your liking:
<div id="solution2" data-value='{"name": "solution2"}'></div>
JSON.parse(document.getElementById('solution2').dataset.value)
3.) Use the script tag and choose a different content type than text/javascript or application/javascript
<script id="solution3" type="script" type="text/json">{"name": "solution3"}</script>
JSON.parse(document.getElementById('solution3').innerHTML)
Live demo
http://jsfiddle.net/bikeshedder/sbjud/
Personal note
It might sound boring, but the first option is probably the best choice. It is fast, requires as little code as possible and just works. I don't see a reason why you would want to have your data in a string first if you can have it as JavaScript data right away.
You could add an inline script if you are serving up a full page... Of course this would pollute the global namespace.
<script>
var tkts = <%= items %>;
</script>
If you are using AJAX to get this page... then break it into two AJAX requests... one of them gets the template, and the other one can get the list of items (as a JSON request). They could run in parallel so it might even be quicker.
<FORM METHOD=GET ACTION="../cgi-bin/mycgi.pl">
<INPUT NAME="town"><BR>
<INPUT TYPE=SUBMIT>
</FORM>
Will redirect us to
../cgi-bin/mycgi.pl?town=example
but I want to redirect to
../cgi-bin/mycgi.pl?example
It means, remove the parameter name in the URI?
I try to google, but found nothing like this.
Thanks in advance.
No, you cannot remove the parameter name in standard GET request.
Its a common way, how http request are made. All parameters must have a name and therefore it will be a couple (name=value) for each input.
What you are trying to achieve may acomplish javascript processing of the submitted form. Which will take the input named town and redirect user to such URL.
Something like:
<script type="text/javascript">
var elem = document.getElementById("town");
window.location = "path_to_script/mycgi.pl?"+elem.value
</script>
But in html you have to specify your town as following
<input type="text" name="town" id="town" />
GET will always post the variables with query string starting as ?variable=value&variable2=value2"
What you could do is have the form post to itself by removing the ACTION tag, and use method=post. Then parse $_REQUEST['POST'] and build the url you need, and redirect to the built url.