I'm facing a problem with Ajax enabled forms, so this is the scenario. I have 2 blocks, the first one has some buttons and the other one has a form ,constructed using the Form API.
When I click any of the buttons in the first block and AJAX Request is sent to the server, then in my callback function it replaces the second's block form data with new values, for doing this I call the drupal_get_form function, so the code for the callback is more or less like this:
$form = drupal_get_form('panorama_info_form');
print render($form);
And the elements of the form have the following style:
//Text field for title
$form['panorama_titulo'] = array(
'#type' => 'textfield',
'#title' => t('Nombre del panorama'),
'#default_value' => $panorama['titulo'],
'#description' => t('Nombre del panorama'),
'#size' => 40,
'#maxlenght' => 120,
'#required' => TRUE,
'#prefix' => '<div id="panorama_titulo_div">',
'#suffix' => '</div>',
'#ajax' => array(
'callback' => 'panorama_info_form_callback',
'wrapper' => 'panorama_titulo_div',
'method' => 'replace',
'effect' => 'fade',),);
Now, in my jQuery Http 200 success function I replace the old form with the response data like this:
function reload_element(data){
$("#panorama-info-form").replaceWith(data);
}
where data is the rendered form.
This works, and I can see my form with the new default values that I declared, however after the form is replaced, ajax is no longer triggered by events. What I mean is that before I replaced the form with jQuery, it used to work, the value was sent to the server and the callback function declared for the textfield was in fact getting called. However after the replacement, no more ajax request... Why is this happening??? I guess that's because there's some kind of script that uses the form's element's classes to attach functions dynamically to it... Maybe that could be one reason. How could I fix this??? Thanks a lot.