I have the following view and controller. The code works fine. The
controller action basically defines a select dropdown form as a
component. A change in the dropdown will cause the appearance of an
alert dialog.
However, I noticed that when the "ajax=True" in place of "ajax=True"
in the view, the dialog no longer appears and there are no errors seen
in the javascript console. Why is this so? I am asking this as part of
my troubleshooting to a bigger related problem which I will write
soon.
#console.html
<script>
<!-- Load comment component based on dropdown selected -->
$(document).ready(function(){
$('select#conversation_dropdown_text').change(function(){
alert('meow');
});
})
</script>
<h1>Conversation</h1>
<div id="sidebar-header">
{{ block sidebar-header }}
{{=LOAD('comment', 'conversation_dropdown.load',
args=[request.args[0]], ajax=False)}}
{{ end }}
</div>
#comment.py
def conversation_dropdown():
'''This action returns a dropdown component'''
# Pull the worksheet requested
w = db.worksheet(request.args(0))
# Create the manage the conversation selector dropdown
conversation_dropdown = SQLFORM.factory(
Field('text', label='Select a conversation',
requires=IS_IN_DB(db(db.question.worksheet==w), 'question.id',
'question.text', orderby='question.id')), _id='conversation_dropdown',
table_name="conversation_dropdown")
#hide the submit button
submit = conversation_dropdown.element('input',_type='submit')
submit['_style'] = 'display:none;'
#process form dropdown
if conversation_dropdown.accepts(request.vars, session):
current_conversation = request.vars.text
elif conversation_dropdown.errors:
response.flash = 'Form has errors'
return {'conversation_dropdown':conversation_dropdown}