Nieuw lid |
|
Hallo
Ik ben niet zeker of dit in dit forum gedeelte past of beter in bij javascript, maar dan moet het maar verplaatst worden.
Mijn vraag:
Ik gebruik chosen om de multiselect wat dynamischer te maken, zie :http://harvesthq.github.com/chosen/.
Het werkt allemaal heel goed, maar als ik dit oproep via ajax dan werkt het niet meer. IK ben geen javascripter en weet dus niet dadelijk hoe dit op te lossen.
Ik werk met cakephp en dit zijn de twee broncodes
van de view met de ajax request:
<div id="searchField">
<?php
echo $this->Form->create('SearchForQuestions');
?>
<fieldset>
<legend><?php __('Zoeken'); ?></legend>
<?php echo $this->Form->input('mainTopic',array('label' => 'Vak:','empty' => true)); ?>
<div id="loader" style="display:none"><?php echo $this->Html->image('loader.gif'); ?></div>
<div id="childTopics"></div>
</fieldset>
<?php
echo $ajax->observeField('SearchForQuestionsMainTopic',array('url' => array( 'action' => 'get_children' ),'frequency' => 0.2,'indicator' => loader',
'update' => 'childTopics' ));
echo $this->Form->end();
?>
<div id="searchField"> <?php echo $this->Form->create('SearchForQuestions'); ?> <fieldset> <legend><?php __('Zoeken'); ?></legend> <?php echo $this->Form->input('mainTopic',array('label' => 'Vak:','empty' => true)); ?> <div id="loader" style="display:none"> <?php echo $this->Html->image('loader.gif'); ?></div> <div id="childTopics"></div> </fieldset> <?php echo $ajax->observeField('SearchForQuestionsMainTopic',array('url' => array( 'action' => 'get_children' ),'frequency' => 0.2,'indicator' => loader ', 'update' => 'childTopics' )); echo $this->Form->end(); ?>
De view welke wordt opgeroepen met ajax
<?php echo $this->Html->css(array('chosen'),'stylesheet', array('inline' => false ) ); ?>
<h1>Chosen</h1>
<div class="side-by-side clearfix">
<div>
<em>Multiple Select with Groups</em>
<select data-placeholder="Your Favorite Football Team" style="width:350px;" class="chzn-select" multiple tabindex="6">
<option value=""></option>
<option>Dallas Cowboys</option>
<option>New York Giants</option>
<option>Philadelphia Eagles</option>
<option>Washington Redskins</option>
<optgroup label="NFC NORTH">
<option>Chicago Bears</option>
<option>Detroit Lions</option>
<option>Green Bay Packers</option>
<option>Minnesota Vikings</option>
</optgroup>
</select>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js" type="text/javascript"></script>
<script src="/experimenten/js/chosen.proto.js" type="text/javascript"></script>
<script type="text/javascript">
document.observe('dom:loaded', function(evt) {
var select, selects, _i, _len, _results;
if (Prototype.Browser.IE && (Prototype.BrowserFeatures['Version'] === 6 || Prototype.BrowserFeatures['Version'] === 7)) {
return;
}
selects = $$(".chzn-select");
_results = [];
for (_i = 0, _len = selects.length; _i < _len; _i++) {
select = selects[_i];
_results.push(new Chosen(select));
}
deselects = $$(".chzn-select-deselect");
for (_i = 0, _len = deselects.length; _i < _len; _i++) {
select = deselects[_i];
_results.push(new Chosen(select,{allow_single_deselect:true}));
}
return _results;
});
</script>
<?php echo $this->Html->css(array('chosen'),'stylesheet', array('inline' => false ) ); ?> <h1>Chosen</h1> <div class="side-by-side clearfix"> <div> <em>Multiple Select with Groups</em> <select data-placeholder="Your Favorite Football Team" style="width:350px;" class="chzn-select" multiple tabindex="6"> <option value=""></option> <option>Dallas Cowboys</option> <option>New York Giants</option> <option>Philadelphia Eagles</option> <option>Washington Redskins</option> <optgroup label="NFC NORTH"> <option>Chicago Bears</option> <option>Detroit Lions</option> <option>Green Bay Packers</option> <option>Minnesota Vikings</option> </optgroup> </select> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js" type="text/javascript"></script> <script src="/experimenten/js/chosen.proto.js" type="text/javascript"></script> <script type="text/javascript"> document.observe('dom:loaded', function(evt) { var select, selects, _i, _len, _results; if (Prototype.Browser.IE && (Prototype.BrowserFeatures['Version'] === 6 || Prototype.BrowserFeatures['Version'] === 7)) { return; } selects = $$(".chzn-select"); _results = []; for (_i = 0, _len = selects.length; _i < _len; _i++) { select = selects[_i]; _results.push(new Chosen(select)); } deselects = $$(".chzn-select-deselect"); for (_i = 0, _len = deselects.length; _i < _len; _i++) { select = deselects[_i]; _results.push(new Chosen(select,{allow_single_deselect:true})); } return _results; }); </script>
|