Commit d944d3f3 authored by Sven Franck's avatar Sven Franck

form submit handler via AJAX (replace with JIO later)

parent 87528cef
......@@ -5788,14 +5788,12 @@
));
// enhance
// NOTE: update layout and set .... (hey Romain: bindings)
$(document)
.enhanceWithin()
.off(".init")
// NOTE: set a global click listener for every link that
// wants to open the global popup. This will just store
// a reference on the popup for which content to load
// global popup handler & content shuffle/caching
.on("click", "." + handler, function (e) {
var link = e.target,
reference = link.getAttribute("data-reference"),
......@@ -5811,6 +5809,49 @@
if (rebuild) {
pop.setAttribute("data-rebuild", "true");
}
})
// global form submit and client validation
// TODO: change as pleased
.on("click", ".action_submit", function (e) {
var valid,
form = document.getElementById(e.target.getAttribute("data-form")),
target = e.target.href,
id = form.id,
pointer = "response:" + id,
proceed = function (data, target) {
// changePage with fragment_cache pointer
$.mobile.changePage(target, {"transition": "slide", "data": data});
};
// stop
e.preventDefault();
// validate
// TODO testForClass not working
if ($(form).hasClass("validate")) {
valid = $( form ).triggerHandler( "submitForm" );
} else {
valid = $( form ).serialize();
}
// fetch and proceed
if (valid !== false) {
$.ajax({
"type":"POST",
"url": "foo.php",
"data": valid
}).done(function(data) {
// overwrite cache
// NOTE: FAKE data until working
priv.fragment_cache[id] = priv.getFakeRecords["payment"];
proceed(pointer, target);
}).fail(function(jqXHR) {
// fake it
priv.fragment_cache[id] = priv.getFakeRecords["payment"];
proceed(pointer, target);
});
}
});
}
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment