Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorsuthern
    I've seen a few posts on here from people who have some working ajax code. Would you care to share it with us? Things like the view code, controller code, and any tips/hints that you had to do to get it working would be appreciated. Thanks!
    • CommentAuthorhpatoio

    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>


    <%= javascript_include_tag 'prototype' %>

    in the layout

    -- Simone

    • CommentAuthordelia

    is there a way to change the parent div id ("ajaxResult" in this case) after the ajax call?? from the _ajaxPartial.tpl or from another place. If i put javascript code in the partial file, it disappears .....

    thanks in advance!!
    • CommentAuthorsuthern
    Why would you want to change the name of the div AFTER the ajax call? Are you sure that dynamically changing the name of the div is a good idea?
    • CommentAuthordelia
    hi suthern,

    what i want to do is the following:

    i have a list of items like that:

    <div id="item1">Item 1 (associated with a link that permits the update through ajax: shows a in-place editor and update) </div>
    <div id="item2">Item 2 (associated with a link that permits the update through ajax: shows a in-place editor and update) </div>

    I want to add new rows through ajax, but i need to set the id of the new item (for laters updates).

    Sorry, but i cant explain better......

    Do you know what i mean???? It's a CRUD system but using only AJAX calls ...
    • CommentAuthorsuthern

    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.).

    • CommentAuthorasejua

    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(
            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 ...
            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">

    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.