⚠ 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

lock filds to edit



masoud1990
  • profile picture
  • Member

Posted 10 June 2012 - 09:50 AM

hi all
i want lock a flid for edit but show it in edit page

for example i have 'username' 'password' and id filds and only i want edit password but user name and id show on edit page
what can i do for this?

noskov.biz
  • profile picture
  • Member

Posted 10 June 2012 - 10:16 AM

Hi there!

You can easily use function change_field_type, for example:

$crud->change_field_type('username', 'readonly');

masoud1990
  • profile picture
  • Member

Posted 10 June 2012 - 11:12 AM

thank you very much

masoud1990
  • profile picture
  • Member

Posted 10 June 2012 - 14:00 PM

Tahts not working
if i want add new item its loked
i want only in edit its locked

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 10 June 2012 - 14:42 PM

You can try something like this:


function users_example($operation = null) {
$crud = new grocery_CRUD();

$crud->set_table('users');

if($operation == 'edit')
{
$crud->change_field_type('username', 'readonly');
}

$output = $crud->render();

$this->_example_output($output);
}


noskov.biz
  • profile picture
  • Member

Posted 10 June 2012 - 14:42 PM

If you want disable only edit, you can use function callback_edit_field. Add to your function this line:


$crud->callback_edit_field('username', array($this, 'readonly_edit_field'));


and then add [b]readonly_edit_field[/b] function:


public function readonly_edit_field($value = '', $key = null)
{
return '<div style="margin:6px 0 0">'.$value.'</div>';
}


Please, read the documentation of API grocery_crud You can find there a lot of helpful things.