0

I'm using the Form api to submit with ajax which works once, but once it's happened the wrapper element has also been replaced by the new ajax content. How can I make sure the content get replaced, but the wrapper element stays there so it can be replaced again?

$form['submit'] = array(
  '#type' => 'submit',
  '#value' => 'submit',
  '#ajax' => array(
      'callback' => 'fung_filter_form_callback',
      'wrapper' => 'view-cont',
      'method' => 'replace',   
) 

For now I've got a workaround by returning the same wrapper in the ajax content, but this seems a bit strange - any ideas?

1
  • Please add the code of the part you define wrapper in, and code of fung_filter_form_callback. Basically now you are telling Drupal to replace element with id view-cont - maybe you replace it with something that does not contain new view-cont?
    – Mołot
    Aug 28 '13 at 8:58
2

If you don't want to 'replace' element with id 'view-cont', use another 'method', like:

'method' => 'append',

And if you in fact want to replace it, modify fung_filter_form_callback to make it return div with that ID again - that way you will replace original div with another div of the same ID, and will be able to repeat that process.

2
  • The second thing you mention is what I have ended up doing. Seems a bit backwards to me - the content of the wrapper should be replaced, not the wrapper itself? But, hey ho it's working :)
    – Chris
    Aug 28 '13 at 10:38
  • @Chris look at this from flexibility point - now you can choose if you want to keep the wrapper or not. If only content was replaced, you would always keep the wrapper and there would be no convenient way to remove it if needed.
    – Mołot
    Aug 28 '13 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.