Hello all,
I am working on an app using web2py and the jquery.mobile plug-in which I upgraded from v1.3.1 to v1.3.2. So far everything is working fine except for the image upload feature. I managed to solve the problem and enable the upload, but I had to hack the jquery.mobile-1.3.2.js source to make it work. I am making this post in order to share my experience.
Here is the situation: when the view to do the upload includes the normal layout file everything works as expected. However, when using the plugin_jqmobile/layout.html, the upload fails with the jquery.mobile message "Error Loading Page" - in short the web2py callback fails. The record does not get inserted, neither does the response.flash error message appear. A couple of long sessions with javascript debugger and reading //
api.jquery.com/submit eventually led me to suspect event.preventDefault() was causing the error. Indeed it was true, when I commented out that line of code, the upload was successful. Below is the modified code snippet from jquery.mobile-1.3.2.js (this problem also exists in jqm v1.3.1)
//bind to form submit events, handle with Ajax
$.mobile.document.delegate( "form", "submit", function( event ) {
var formData = getAjaxFormData( $( this ) );
if ( formData ) {
$.mobile.changePage( formData.url, formData.options );
//event.preventDefault(); //turned this off to enable web2py callbacks
}
});
I am going to proceed with further testing. If there is a better solution, please let me know. Thank you.
In my controller I have the following standard code:
form = SQLFORM(db.documnt)
if form.accepts(request, session):
elif form.errors:
response.flash = 'form has errors...'
return dict(form=form)
And the associated view:
{{#extend 'layout.html'}}
{{extend 'plugin_jqmobile/layout.html'}}
<body>
{{=form}}
</body>