Hi guys..
I am trying out ajax and symfony. I have this select box for
categories.. when it is selected another selectbox with sub
categories, on a separate "table row" below it, is displayed (this row
is first hidden). The only problem now is that the row is displayed
regardless if the ajax remote call manages to get data or not.. I
would rather it didn't show this hidden row if the action (related to
ajax call) doesn't find anything.. It should be possible, right? Any
help is appreciated! thanks!
the template:
<tr>
<th>Category:</th>
<td><?php echo object_select_tag($item, 'getCategoryId', array (
'related_class' => 'Category',
'include_custom' => 'Choose your category!',
)) ?></td>
</tr>
<tr style="display: none;" id="subcat_row">
<th>Subcategory:</th>
<td>
<div id="subcat">
<?php include_partial('subcat', array('subcats' =>
$subcategories)) ?>
</div>
</td>
</tr>
<?php echo observe_field('category_id', array(
'update' => 'subcat',
'url' => 'item/subcatFoo',
'with' => "'id='+$('category_id').value",
'success' => "Element.show('subcat_row')",
)) ?>
_subcat.php
<?php if ($subcats): ?>
<select name='subcategory_id' id='subcategory_id'><option
value=''>Välj här</option>
<?php foreach ($subcats as $subcat) :?>
<?php echo "<option>".$subcat->getName() . "</option>"; ?>
<?php endforeach; ?>
</select>
<?php endif; ?>
success template for action
<?php include_partial('subcat', array('subcats' => $subcategories)) ?>
The action
public function executeSubcatFoo()
{
$var = $this->getRequestParameter('id');
$c = new Criteria();
$c->add(SubCategoryPeer::CATEGORY_ID, $var);
$c->addAscendingOrderByColumn(SubCategoryPeer::NAME);
$subcategories = SubCategoryPeer::doSelect($c);
$this->subcategories = $subcategories;
}
What about if subcategories is null? I want to return some type of
response that tells the ajax call NOT to update anthing...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---