In the View
<div id="ajaxResult"></div>
<h5>Add</h5>
<%= form_remote_tag :url => { :action => :add_field }, :update => "ajaxResult" %>
<%= text_field :myModel, :name %> <%= submit_tag %>
<%= end_form_tag %>
When you push the submit Akelos call the method "add_field" in the controller.
add_field looks like
function add_field() {
$this->fromAjax = $this->params['topic_field'];
$this->renderPartial("ajaxPartial.tpl");
}
the file "_ajaxPartial.tpl" looks like
This from Ajax <b>{fromAjax?}</b>
Remember
<%= javascript_include_tag 'prototype' %>
in the layout
-- Simone
Perhaps you could use id's like 'row1' and 'row2'.
That way the row number is not changed when you change the item (to another item.).
Hi,this is one of the "ajax-related" code I'm working with. I'm using modalbox JS library.
What I've done it's create a helper that prints an icon with a link in each row in the listing view, and clicking it shows a modalbox that loads through ajax that item's edit form whithout leaving the listing page. It's "semi-ajax" cause after saving the form, the page reloads fully, returns to the listing view, but it's quicker than going from one page to another. I've simplified the code a lot for not being boring xD
Helper code:
function link_to_edit(&$record) {
return $this->_controller->url_helper->link_to(
$this->_controller->asset_tag_helper->image_tag('pencil.png'),
array('action' => 'edit', 'id' => $record->getId()),
array('onclick'=>'Modalbox.show(this.href, {title: this.title, width: 430}); return false;',
'title' => $this->_controller->t('Edit '.AkInflector::humanize($this->_controller->model))));
}
The Controller's edit action ( 'device' is a model being edited in this sample ):
function edit() {
if (!empty($this->params['device'])) { // If not device attributes are set ...
$this->device->setAttributes($this->params['device']);
if ($this->Request->isPost() && $this->device->save()) {
// ... here the code with a redirect to the listing page[1]...
}
} else $this->layout = 'modalbox'; // ... let's show the form using modalbox.tpl layout instead of the usual layout
}
This modalbox.tpl layout could be simple like this:
<div id="page_modalbox">
<div id="content">
<div id="modalbox_content">
{content_for_layout}
</div>
</div>
</div>
Of course this method can be used too with actions like add, show, destroy, whatever...
[1]You just need to find a way to keep the listing url through all this process to let the edit action go back to listing once saved. I use a parameter in the icon link that stores the listing url in base64.
Jose
1 to 7 of 7