Welcome Guest, Not a member yet? Register   Sign In
Problem with JEditable
#1

[eluser]RMinor[/eluser]
I am using JEditable to allow in-line editing in my website, but have come across an odd issue. Basically, the functionality works. I can click the item, edit it, and save it. It updates everything in the database, but does not display the new value after editing. I tried both echoing out and returning the value from the controller. I've also tried allowing query strings in the config.php file. Nothing works to display the new value. My Firebug result is a status 200 OK message that is in red instead of the usual black. I looked up what the red color means to find that there is some error, however no error is being reported. If anybody has any ideas on how to fix this please share them. My code is below.

Controller
Code:
public function edit()
{
    $id = $this->input->post('id');
    $name = $this->input->post('value');
    if ($this->Category_model->edit($id, $name)) {
        return TRUE;
    }
    return FALSE;
}

Model
Code:
/**
* Method to edit a category.
*/
public function edit($id, $name)
{
    $value = $this->_createValue($name);
    $query = $this->db->query("UPDATE category SET value = ?, name = ? WHERE id = ?", array($value, $name, $id));
    if ($this->db->affected_rows() == 1) {
        return TRUE;
    }
    return FALSE;
}

/**
* Method to create a value for a category name.
* The goal here is to make everything lower case, replace spaces with dashes, and replace ampersands with the word 'and'.
*/
private function _createValue($name)
{
    $value = strtolower($name);
    $value = str_replace(' ', '-', $value);
    $value = str_replace('&', 'and', $value);
    return $value;
}

View
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;ADMIN PANEL&lt;/title&gt;
&lt;link rel="stylesheet" type="text/css" href="&lt;?php echo base_url(); ?&gt;css/admin-style.css" /&gt;
&lt;style type="text/css"&gt;
.editableSingle button, .editableSingle input {
padding: 3px;
}
&lt;/style&gt;
[removed][removed]
[removed][removed]
[removed]
ddaccordion.init({
headerclass: "submenuheader",
contentclass: "submenu",
revealtype: "click",
mouseoverdelay: 200,
collapseprev: true,
defaultexpanded: [],
onemustopen: false,
animatedefault: false,
persiststate: true,
toggleclass: ["", ""],
togglehtml: ["suffix", "<img src='&lt;?php echo base_url(); ?&gt;images/plus.gif' class='statusicon' />", "<img src='&lt;?php echo base_url(); ?&gt;images/minus.gif' class='statusicon' />"],
animatespeed: "fast",
oninit:function(headers, expandedindices){
  //do nothing
}, onopenclose:function(header, index, state, isuseractivated){
  //do nothing
}
})
[removed]
[removed][removed]
[removed]
$(document).ready(function() {
$('.ask').jConfirmAction();
});
[removed]
[removed][removed]
[removed]
$(document).ready(function() {
     $('.editable').editable('http://www.digrepro.com/admin/categories/edit', {
  indicator : 'Saving...',
  tooltip   : 'Click to Edit',
  submit    : 'OK'
});
});
[removed]
[removed][removed]
&lt;link rel="stylesheet" type="text/css" media="all" href="&lt;?php echo base_url(); ?&gt;css/niceforms-default.css" /&gt;
&lt;/head&gt;
&lt;body&gt;
<div id="main_container">
<div class="header">
  <div class="logo"><img src="&lt;?php echo base_url(); ?&gt;images/logo.gif" border="0" /></div>
  <div class="right_header">Welcome Admin, <a href="&lt;?php echo base_url(); ?&gt;">Visit site</a> &lt;!--| <a href="#" class="messages">(3) Messages</a>--&gt; | <a href="&lt;?php echo base_url(); ?&gt;admin/logout" class="logout">Logout</a></div>
  <div class="jclock"></div>
</div>
<div class="main_content">
  &lt;?php $this->load->view('admin/menu_view'); ?&gt;
  <div class="center_content">
         <div class="left_content">
    &lt;?php $this->load->view('admin/sidebar_view'); ?&gt;
   </div>
   <div class="right_content">
    <h2>Product Categories</h2>
                <p>To edit a category name simply click on it and make your change. Press the "OK" button when done.</p>
    <table id="rounded-corner">
     <thead>
      <tr>
       <th scope="col" class="rounded-company"></th>
                            <th scope="col" class="rounded">Category</th>
       <th scope="col" class="rounded-q4"></th>
      </tr>
     </thead>
     <tbody>
      &lt;?php foreach ($categories as $category) {?&gt;
                      <tr>
        <td></td>
                                <td class="editable" id="&lt;?php echo $category['id']; ?&gt;">&lt;?php echo $category['name']; ?&gt;</td>
        <td><a href="&lt;?php echo base_url(); ?&gt;admin/categories/delete/&lt;?php echo $category['id']; ?&gt;" class="ask"><img src="&lt;?php echo base_url(); ?&gt;images/trash.png" border="0" /></a></td>
       </tr>
                     &lt;?php } ?&gt;
     </tbody>
    </table>
    <a href="&lt;?php echo base_url(); ?&gt;admin/categories/add" class="bt_green"><span class="bt_green_lft"></span><strong>Add Category</strong><span class="bt_green_r"></span></a>
   </div>&lt;!-- end of right content--&gt;
  </div>&lt;!--end of center content --&gt;
  <div class="clear"></div>
    </div> &lt;!--end of main content--&gt;
<div class="footer">
  <div class="left_footer">ADMIN PANEL</div>
  <div class="right_footer"><img src="&lt;?php echo base_url(); ?&gt;images/indeziner_logo.gif" alt="" title="" border="0" /></div>
</div>
</div>
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]InsiteFX[/eluser]
Do a redirect back to page to reload the new data.
#3

[eluser]RMinor[/eluser]
I changed my controller to look like the following...
Code:
public function edit()
{
    $id = $this->input->post('id');
    $name = $this->input->post('value');
    if ($this->Category_model->edit($id, $name)) {
        redirect('admin/categories');
        //return $name;
        //echo $name;
        //return TRUE;
    }
    return FALSE;
}

However, it still does not work. No redirect happens, but the data does get updated in the database. I also tried it with and without the url helper loaded, but that doesn't change anything. Do you think maybe a setting is set wrong somewhere? I have enabled query strings and also turned off gzip as well. I read in other threads that this was the problem for some, but it doesn't make a difference for me.
#4

[eluser]RMinor[/eluser]
Update: I got it working by doing the following:
1) I updated jQuery from V1.5.2 to V1.7.1 (I doubt this had anything to do with it.)
2) I replaced my hard-coded value for which to send the jEditable request with
Code:
&lt;?php echo site_url(); ?&gt;/admin/categories/edit
(This is something I overlooked, but then saw by looking over old threads.)

So basically, to anyone wishing to use this plugin to add in-line editing to the CodeIgniter website, make sure you use site_url(); for the value to which you want you jEditable request sent. Also, as said by others here, be sure to echo the value from the controller back to the view.




Theme © iAndrew 2016 - Forum software by © MyBB