This first part works fine on its own. It's when I try to make this part of an AJAX component inside another page that it fails.
Model:
db.define_table('temp_pics',
Field('image', 'upload', required=True, notnull=True, requires=IS_IMAGE()))
Controller:
# This will reload itself and allow changing the photo after submission.
def upload_temp():
record = db.temp_pics(request.args(0))
pic_upload = SQLFORM(db.temp_pics, record, upload=URL('download'))
if pic_upload.process(formname='pic_upload').accepted:
redirect(URL('upload_temp', args=id),client_side=True)
return dict(pic_upload=pic_upload)
View:
{{=pic_upload}}
Now I want to put this in a different view using:
{{=LOAD('default', 'upload_temp','upload_temp.load',ajax=True)}}
If I set ajax=False, it will work, but reload the whole page, which fully defeats the purpose.
Somewhere you need to have this script referenced (and you'll have to download that script online first):
src="{{=URL('static', 'js/jquery.form.js')}}"
And in the default/upload_temp.html (and identical upload_temp.LOAD), you need to have this:
{{=pic_upload}}
<script>
//<!--
$('document').ready(function() {
$('pic_upload').ajaxForm({dataType: 'script', // <-- like the ':eval' target in ajax() function
});
});
</script>
Is there a way to make this work? The book just says AJAX doesn't do forms, but doesn't go on to explain how I should handle this sort of thing. Any help is much appreciated!