Hello,
I have a curious problem:
When sending an #ahah callback drupal embedds the returned code into an additional div-container in the wrapper. This is very annoying since the "new" div has not the same dimensions as the old one (new ones parent). I use it as a frame for dragging other containers with some javascript but it doesn't work with the new div which hasn't got fixed dimensions.
For better understanding here the important code and some output:
/**
* #uc_order_tag_style_frame is my wrapper and contains some divs which are draggable via javascript in the parents area.
*/
function theme_edit_tag_style($image_url, $nid, $placeholder, $data = array()) {
// snip...
$output .= '<div id="uc_order_tag_style_frame" style="position: relative; background: url('.$image_url.') no-repeat center; width: 400px; height: 200px;">';
$output .= theme('style_frame_content', $data, $placeholder);
$output .= '</div>';
// snap...
return $output;
}
/**
* This is the form which contains the 'evil' #ahah callback
*/
function uc_order_tag_edit_product_tag_style_form($form_state, $data, $placeholder) {
// snip
$form['apply'] = array(
'#type' => 'submit',
'#value' => t('apply changes'),
'#ahah' => array(
'path' => 'admin/uc_order_tag/font/apply',
'wrapper' => 'uc_order_tag_style_frame',
'effect' => 'fade',
'event' => 'click',
),
);
return $form;
}
/**
* This is the #ahah callback function
*/
function uc_order_tag_font_apply_js() {
// snip ...
$output = theme_style_frame_content($data, $placeholder);
dpm($output); // <div id="element1" style="...."> </div><div id="element2" .....> </div>
drupal_json(array('status' => TRUE, 'data' => $output));
exit;
}
As you can see $output only contains a few arranged div-containers. So the HTML should look similar to the following after fireing the #ahah callback:
<div id="uc_order_tag_style_frame" style="position: relative; background: url(background.png) no-repeat center; width: 400px; height: 200px;">
<div id="element1" ...> </div>
<div id="element2" ...> </div>
</div>
But this is what I get:
<div id="uc_order_tag_style_frame" style="position: relative; background: url(background.png) no-repeat center; width: 400px; height: 200px;">
<div style="display: block;">
<div id="element1" ...> </div>
<div id="element2" ...> </div>
</div>
</div>
Any ideas what's happening here and how I could fix this?
Thanks for reading,
haggins
Comments
Solution
Encountered the same problem when trying to replace table rows with ahah. Nasty.
Found a general workaround by adding a new behavior to my module that includes this code:
(For some reason I couldn't understand, the event is fired twice on my form. But for me is ok.)
Where did You Insert This Code?
Peter, where did you insert this code?
I'm having a similar problem to what haggins described. I'm using AHAH to replace a piece of a composite image, and the new image appears slightly above and to the right of the original.
I've tried using your example with drupal_add_js, but my editor (Komodo) throws syntax errors.
add it as a behavior
I had the same question Mark, I found my answer by searching "drupal behaviors": http://drupal.org/node/205296
I just put peterpoe's code at the top of my module's .js file like this:
and it's working great for me.
Thank you - this solved my
Thank you - this solved my problem.
I am having problems in
I am having problems in Drupal 6 with the extra
I have tried to see what is going on with Firebug. I can confirm that that the module's js file is loaded, but a break-point set on the example function above is never hit. Is there something that I need to do to attach behaviors to the new DOM elements in order to have this behavior fire? Other thoughts of what might be wrong?
Until I get this fixed, I have the odd behavior using Drupal 6 AHAH's functionality that the new row of the table is inserted entirely into the first column of the existing table format. Any help would be much appreciated.
Lars Toomre
Managing Director
Toomre Capital Markets LLC
http://lars.toomre.com/
to add this javascript block inline in a #after_build
Worked like a charm-- thank you :)
For me, I slipped it into my #after_build as 'inline' javascript:
Using this technique, I can directly massage my #ahah output to produce to my liking and insert directly in my CCK
list, clientside. I don't know how hackish this is, but it works.
--
http://drupaltees.com
80s themed Drupal T-Shirts
unset prefix and suffix
I think what you are seeing is addressed by this line
from the function poll_choice_js() code sample on http://drupal.org/node/331941. You can see another example in the code sample for function quicktabs_ahah() on the same page.
Thanks for the post reference
I was able to figure a lot out from studying the examples.
I've emulated the second example on the referenced link (for quick tabs), and while it has improved functionality in a few areas, my image is still jumping up and to the right, but I think I know why now.
Using Firefox and FireBug, I found that prior to making the AHAH call to change the image, my css for the division looked like this:
After the AHAH call, it looks like this:
This is the same addition as in the original post by Haggins. What I'm not clear on is how to apply the behavior code in the response. Anyone have experience with this? Any additional info greatly appreciated.
I was able to figure it out...
I looked more closely at Haggins original code, and noticed he was putting css
So.....I added the following to my $output:
Turns out the
<?php <div style="display: block;>?>isn't what was moving the image, the missing cssI expect that soon after I post this, someone will reply and tell me the "right way" to do this, but that's ok.
There's something else going on
I am also getting an extra div tag. I can look at the response coming back from the server and the div is not in the response. Then I looked at the javascript and on line 153 of ahah.js, there is
var new_content = $('<div></div>').html(response.data);Pretty much the first thing the code does when it gets the info back from the server is put an extra div around it.
It's a long time ago but I
It's a long time ago but I will share my solution:
I ended up in creating my custom $.ajax call within my javascript file which gives me a lot more flexibility.
@haggins how ?
@haggins how ?
@vikingjs i made that :
figureslibres.cc