to avoid undefined attribute errors, give different ids to the create table form and add fields form; then use the .live() method directly after a selector as recommended

This commit is contained in:
Marc Delisle
2010-09-26 07:22:58 -04:00
parent 8cf1e880f5
commit 14c02c1e67
2 changed files with 79 additions and 63 deletions

View File

@@ -2035,17 +2035,15 @@ $(document).ready(function() {
}); });
/** /**
* Attach event handler for submission of create table form * Attach event handler for submission of create table form (save)
* *
* @uses PMA_ajaxShowMessage() * @uses PMA_ajaxShowMessage()
* @uses $.PMA_sort_table() * @uses $.PMA_sort_table()
* @uses window.parent.refreshNavigation() * @uses window.parent.refreshNavigation()
* *
* The create_table_form whose action is tbl_create.php is the
* one which is ajaxified; in this form the action could be
* tbl_addfield.php but it's not ajaxified yet.
*/ */
$("#create_table_form").attr('action').is('tbl_create.php').find("input[name=submit_num_fields], input[name=do_save_data]").live('click', function(event) { // .live() must be called after a selector, see http://api.jquery.com/live
$("#create_table_form input[name=do_save_data]").live('click', function(event) {
event.preventDefault(); event.preventDefault();
/** /**
@@ -2055,14 +2053,6 @@ $(document).ready(function() {
PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
$(the_form).append('<input type="hidden" name="ajax_request" value="true" />'); $(the_form).append('<input type="hidden" name="ajax_request" value="true" />');
if($(this).attr('name') == 'submit_num_fields') {
//User wants to add more fields to the table
$.post($(the_form).attr('action'), $(the_form).serialize() + "&submit_num_fields=" + $(this).val(), function(data) {
$("#create_table_dialog").html(data);
}) //end $.post()
}
else if($(this).attr('name') == 'do_save_data') {
//User wants to submit the form //User wants to submit the form
$.post($(the_form).attr('action'), $(the_form).serialize() + "&do_save_data=" + $(this).val(), function(data) { $.post($(the_form).attr('action'), $(the_form).serialize() + "&do_save_data=" + $(this).val(), function(data) {
if(data.success == true) { if(data.success == true) {
@@ -2112,8 +2102,34 @@ $(document).ready(function() {
PMA_ajaxShowMessage(data.error); PMA_ajaxShowMessage(data.error);
} }
}) // end $.post() }) // end $.post()
} // end elseif() }) // end create table form (save)
}) // end create table form submit button actions
/**
* Attach event handler for create table form (add fields)
*
* @uses PMA_ajaxShowMessage()
* @uses $.PMA_sort_table()
* @uses window.parent.refreshNavigation()
*
*/
// .live() must be called after a selector, see http://api.jquery.com/live
$("#create_table_form input[name=submit_num_fields]").live('click', function(event) {
event.preventDefault();
/**
* @var the_form object referring to the create table form
*/
var the_form = $("#create_table_form");
PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
$(the_form).append('<input type="hidden" name="ajax_request" value="true" />');
//User wants to add more fields to the table
$.post($(the_form).attr('action'), $(the_form).serialize() + "&submit_num_fields=" + $(this).val(), function(data) {
$("#create_table_dialog").html(data);
}) //end $.post()
}) // end create table form (add fields)
}, 'top.frame_content'); //end $(document).ready for 'Create Table' }, 'top.frame_content'); //end $(document).ready for 'Create Table'

View File

@@ -610,7 +610,7 @@ document.onkeydown = onKeyDownArrowsHandler;
} }
?> ?>
<form id="create_table_form" method="post" action="<?php echo $action; ?>"> <form id="<?php echo ($action == 'tbl_create.php' ? 'create_table' : 'append_fields'); ?>_form" method="post" action="<?php echo $action; ?>">
<?php <?php
echo PMA_generate_common_hidden_inputs($_form_params); echo PMA_generate_common_hidden_inputs($_form_params);
unset($_form_params); unset($_form_params);