this is my working solution now, i changed it a little bit.
i try to design it as a standalone addition without touching the
original iui.js
i copy the most of code and only change this lines
- in "encode" from "=" to "/"
- in submitRestForm from "?" to "/"
(i changed the order of select / input / checkbox to fit my personal
order of the path)
one problem:
1. i can not hook completly into the "big onlick" function i need a
additional useless target to not fire the last function from the "big
onlick function"
2. i need to define the function findParent twice
addtional todo:
- do something how to define the order of the input elements as
tagname list
- or as the input name list so i can define exactly the rest path
- or like the idea which you described here:
> You should be able to add a couple of lines to the submitForm routine
> to assemble your 'restful path' in the "action" string that is currently
> coming from form.action and being passed to iui.showPageByHref().
so i can define it like this with the names:
form.action = "search/type/{user_type}/name/{search_for_name}
CodeSnippets:
additional RestForm.js
(function() {
addEventListener("click", function(event)
{
var link = findParent(event.target, "a");
if (link)
{
if (link.getAttribute("type") == "submit_rest")
submitRestForm(findParent(link, "form"));
else
return;
event.preventDefault();
}
}, true);
function submitRestForm(form)
{
iui.showPageByHref(form.action + "/" + encodeRestForm(form), null,
form.method);
}
function encodeRestForm(form)
{
function encode(inputs)
{
for (var i = 0; i < inputs.length; ++i)
{
if (inputs[i].name)
args.push(inputs[i].name + "/" + encodeURIComponent(inputs
[i].value));
}
}
var args = [];
encode(form.getElementsByTagName("select"));
encode(form.getElementsByTagName("input"));
encode(form.getElementsByTagName("textarea"));
return args.join("/");
}
function findParent(node, localName)
{
while (node && (node.nodeType != 1 || node.localName.toLowerCase() !
= localName))
node = node.parentNode;
return node;
}
})();
now my a link i changed like this in haml
%a.whiteButton{ :type=>"submit", :href=>"#"} Search
to
%a.whiteButton
{ :type=>"submit_rest", :href=>"#",
:target=>"_do_nothing_in_default_onclick_event"}
Search
On 15 Okt., 23:43, Sean Gilligan <[email protected]> wrote:
> MN wrote:
> > i have a restful path for my application:
>
> > get '/search/type/:user_type/name/:search_for_name'
>
> Using standard form GET query parameters is restful, too. If adding an
> option for query parameters is possible/easy you should try that.
>
>
>
> > and with iui i like to make a form with two input fields
>
> And those two input fields need to be put into the URL path?
>
> > but how i can do it?
>
> It's probably easiest to patch iUI to do this. Use either the iui-0.40-dev1
> zip release or the latest version from Mercurial. You should be able to
> add a couple of lines to the submitForm routine to assemble your 'restful
> path' in the "action" string that is currently coming from form.action and
> being passed to iui.showPageByHref().
>
> > i like that my form uses the input values and create a get?
>
> > is there some automatic way?
>
> Not yet. If you create an Issue for this in the issue database, we'll
> at the very least think about creating an extension hook so you can do
> this without modifying iui.js itself.
>
> > i think the showPageByHref is the right function for it?
>
> Yes. (as explained above)
>
> -- Sean
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"iPhoneWebDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/iphonewebdev?hl=en
-~----------~----~----~----~------~----~------~--~---