Somehow, this question never made it to my previous post [http://
groups.google.com/group/cake-php/browse_thread/thread/45442ab30ec579b/
6378626e3a27701e#6378626e3a27701e].  It's like the Google Group lost
my post, so I apologize if this shows up twice.

After a little bit of work and help from francky06l here in the Google
Group, I am now appending data to a div that has data in it already.
Let me show the basic code so everyone knows what's going on:

-----------------------------------------------------------------------
/** main template code **/

   <?php foreach ($tests as $test): ?>
      <?php echo $ajax->link("Add More Tests", "/tests/ajaxAddTest/
{$id]}",
array('update'=>'newData')); ?>
   <?php endforeach; ?>

<div id="originalData">existing data here</div>
<div id="newData"></div

/** END main template code **/
-----------------------------------------------------------------------
/** example ajax_add_test.thtml view **/
<?php
   $ajax->div('dataControl');
   $data = $this->renderElement('elem_add_test', array('form' =>
$form));
   $js =  "new Insertion.Bottom('data', $data)";
   echo  $javascript->codeBlock($js, false);
   $ajax->divEnd('dataControl');
?>
/** END ajax_add_test.thtml view**/
-----------------------------------------------------------------------
/** example elem_add_test.thtml **/
<?php if (!empty($form)) { ?>
    <?php foreach ($form['Field'] as $field): ?>
      <?php echo $html->input('Form/field'. $field['id']); ?>
    <?php endforeach; ?>
<?php } ?>
/** END elem_add_test.thtml**/
-----------------------------------------------------------------------

Ok, so what I'm doing is this:  When the user clicks on the ajax link
in the main template, the controller action (ajaxAddTest) does some
work, sets the $form array, and renders ajax_add_test.thtml.  As you
can see in ajax_add_test, I'm don't want to overwrite the data in the
newData div, I simply want to append new data into it, keeping the old
data.

So, I go and render an element (elem_add_test.thtml) passing in the
$form.  I then take the result of that element render and pass it into
the javascript code block to append.

There are two problems I'm having.

#1) The data overwrites the newData div each time instead of appending
to it.  If I change the ajax_add_test view to the following code
snippet (not using an element), the text NEW TEST DATA appends
properly, never overwriting what was in the newData div.

/** example ajax_add_test.thtml view **/
<?php
   $ajax->div('dataControl');
   $js =  "new Insertion.Bottom('data', 'NEW TEST DATA <br>')";
   echo  $javascript->codeBlock($js, false);
   $ajax->divEnd('dataControl');
?>
/** END ajax_add_test.thtml view**/

Any suggestions or alternate ways to achieve this update process to a
div?

#2) The rendered elements populated into the newData div never seem to
have any style.  They lose all the styling applied elsewhere on the
site.  This a large stumbling block that I need to solve somehow.

Any help would be greatly appreciated!

Dustin Weber


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to