[support] jQuery in form not active after ajax

Marco Lechner - in medias res lechner at webgis.de
Tue Aug 23 14:21:30 UTC 2011


Hi, I added a slider to form-element using field-suffix including jQuery.

<code>
...
'outlinewdidth' => array(
    '#type' => 'textfield',
    '#title' => t('Outline width'),
    '#field_suffix' => "
<div style='width: 256px;' id='edit-outlinewidth_slider'></div>
<script
type='text/javascript'>jQuery(document).ready(function(){jQuery('#edit-outlinewidth_slider').slider({range:'min',value:
jQuery('#edit-outlinewidth').val(),min:0,max:5,step:0.01,slide:function(event,
ui ){jQuery('#edit-outlinewidth').val(ui.value);}});});</script>"
...
</code>

The part of the form is changed by an ajax-event. The slider is not
available after this. The jQuery script is returned by the callback
function but doesn't seem to be executed after the form part is changed
by ajax.

I thought it's because of the jQuery(document).ready(function(){} but
even putting my jQuery it into the <div> using

<div style='width: 256px;' id='edit-outlinewidth_slider'
onload=\"jQuery('#edit-outlinewidth_slider').slider({range:'min',value:
jQuery('#edit-outlinewidth').val(),min:0,max:5,step:0.01,slide:function(event,
ui ){jQuery('#edit-outlinewidth').val(ui.value);}});\"></div>

doesn't work.

How to manage this task?

Marco



More information about the support mailing list