Jump to content


readonly on edit screen, need help, please

readonly change_field_type callback

  • Please log in to reply
2 replies to this topic

#1 Ron

Ron

    Member

  • Members
  • PipPip
  • 19 posts

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');  
        }
}


#2 Ron

Ron

    Member

  • Members
  • PipPip
  • 19 posts

Posted 17 April 2014 - 12:24 PM

Anyone? This would help me tremendously.



#3 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 17 April 2014 - 07: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 ;)







Also tagged with one or more of these keywords: readonly, change_field_type, callback

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users