I have a form containing a text field and the submit button on a jQuery-UI
modal. The modal will be shown if the user clicks on a link on the page. If
the user clicks on the submit button of the form on the modal, a database
row should be updated. However, the form does not get processed
successfully if it is loaded on a modal.
Here is the code in the controller:
def ajax1():
editDetailsForm = SQLFORM.factory(
Field('zip',label="zip"),
)
if editDetailsForm.process().accepted:
response.flash = "Accepted"
db(db.auth_user.id == auth.user.id).update(zip=request.vars[1])
else:
response.flash = "NOT Accepted"
return dict(editDetailsForm = editDetailsForm, zip = zip)
@auth.requires_login()
def ajax():
return dict()
and here is the code in the views:
# for ajax.html:
{{extend 'layout.html'}}
{{=LOAD('default','_ajax.load', ajax=True, user_signature=True)}}
{{=response.toolbar()}}
# for ajax1.html:
<script type="text/javascript">
$(document).ready(function() {
$('div#thedialog').dialog({ autoOpen: false })
$('#thelink').click(function(){ $('div#thedialog').dialog('open'); });
})
</script>
<div id="thedialog" title="Download complete">
{{=editDetailsForm}}
</div>
<a href="#" id="thelink">Clickme</a>
Please note that the zip field is added to the user table. What baffles me
is that if you replace the ajax1 function and ajax1.html with the ajax
function and ajax.html, the modal works flawlessly and the database will be
successfully updated. Please let me know if my code contains any errors or
if you know how to resolve this issue.
Thanks!
=======
This will be accepted:
View:
{{extend 'layout.html'}}
<script type="text/javascript">
$(document).ready(function() {
$('div#thedialog').dialog({ autoOpen: false })
$('#thelink').click(function(){ $('div#thedialog').dialog('open'); });
})
</script>
<div id="thedialog" title="Download complete">
{{=editDetailsForm}}
</div>
<a href="#" id="thelink">Clickme</a>
#Controller
def ajax():
editDetailsForm = SQLFORM.factory(
Field('zip',label="zip"),
)
if editDetailsForm.process().accepted:
response.flash = "Accepted"
db(db.auth_user.id == auth.user.id).update(zip=request.vars[1])
else:
response.flash = "NOT Accepted"
return dict(editDetailsForm = editDetailsForm, zip = zip)
--