⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

readonly on edit screen, need help, please



Ron
  • profile picture
  • Member

Posted 31 March 2014 - 12:45 PM

Is there a way to make a field readonly in the edit screen only when there is a value already entered, and if blank or "0000-00-00 00:00:00" then the user is able to enter a date? The code below is not working, once I hit Update the "Loading, updating changes..." just runs in a loop and will not execute. I think the callback_before_update is probably not the right way of doing this.

$crud->callback_before_update(array($this,'check_Original_ETA'));



function check_Original_ETA($value, $primary_key)
{
        $this -> db -> select('Original_ETA');
		$this -> db -> from('dbname');
		$this -> db -> where('id = ' . "'" . $primary_key . "'"); 
		$this -> db -> limit(1);
		$query = $this -> db -> get();
        $row = $query->row();


        //$query->result();
        
        $str = $row->Original_ETA;

        if ($str != '0000-00-00 00:00:00')
        {
        $crud->change_field_type('Original_ETA', 'readonly');  
        }
}

Ron
  • profile picture
  • Member

Posted 17 April 2014 - 12:24 PM

Anyone? This would help me tremendously.


Amit Shah
  • profile picture
  • Member

Posted 17 April 2014 - 19:04 PM

well my friend, i will recommend you try and understand what are callbacks for. You applied the wrong callback here.
It should be rather callback_edit_field rather then callback_before_update

 

callback_edit_field can surely work but then u have to return the correct outputs of each field by your own.

Rather than that, i will recommend you mark fields readonly by following the mentioned steps

1 - $crud-getState() == 'edit'    //check if the state is edit.. then we apply our rules

2 - //retrieve the segments in the url.. and identify the position of the primary key that you trying to edit

for eg: http://www.example.com/user/edit/1 is the url.. then your segment is 2 (0 - user, 1 - edit, 2 - 1)

3 - now retrieve the row from the table and perform the checks that you wanted to do with and mark the field readonly wherever required

 

Happy GCing ;)