⚠ 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 only in edit?



ceroberoz
  • profile picture
  • Member

Posted 11 February 2014 - 16:39 PM

how to add the field_type('mycolumn','readonly') only in edit if I have a function like this?

public function users(){
		if (!$this->ion_auth->logged_in()){
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}else{
		$crud = new grocery_CRUD();

		//$crud->set_theme('twitter-bootstrap');
		$crud->set_subject('User');
		$crud->set_table('users');


		$crud->columns('first_name', 'last_name', 'email','address','city','postal_code', 'phone', 'groups', 'active')
			 ->fields('first_name', 'last_name', 'email', 'address','city','postal_code','phone', 'groups', 'active', 'change_password', 'edit_password', 'edit_password_confirm')

			 ->field_type('email','readonly')
			 ->add_fields('email', 'first_name', 'last_name','address','city','postal_code', 'phone','groups', 'password', 'password_confirm')
			 ->edit_fields('email', 'first_name', 'last_name','address','city','postal_code', 'phone', 'groups', 'active', 'change_password', 'edit_password', 'edit_password_confirm') 
			 ->set_relation('city','default_cities','name')
			 ->set_relation_n_n('groups', 'users_groups', 'groups','user_id','group_id','description')
			 ->change_field_type('change_password', 'true_false')
			 ->change_field_type('edit_password', 'password')
			 ->change_field_type('edit_password_confirm', 'password')
			 ->set_rules('change_password', 'Change password', 'callback__change_password_check')
			 ->set_rules('edit_password', 'Password', 'min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']')

			 ->callback_edit_field('change_password',array($this,'_cb_change_password_field'))
			 ->callback_edit_field('edit_password', array($this, '_cb_empty_password_input_field'))
			 ->callback_edit_field('edit_password_confirm', array($this,'_cb_empty_password_confirm_input_field'))
			 ->callback_before_update(array($this, '_cb_user_password_update'));

			$output = $crud->render();

			$this->kekgwpeduliaja($output);
		}
	}

Thanks!


Amit Shah
  • profile picture
  • Member

Posted 12 February 2014 - 08:26 AM

Hi ceroberoz

 

There is a simple solution. Use

if ($crud->getState() == "edit") {

       $crud->field_type('email','readonly')

}

 

This is mark the Email field to be readonly if it is in edit state.


ceroberoz
  • profile picture
  • Member

Posted 12 February 2014 - 12:20 PM

Hi ceroberoz

 

There is a simple solution. Use

if ($crud->getState() == "edit") {

       $crud->field_type('email','readonly')

}

 

This is mark the Email field to be readonly if it is in edit state.

cool!, now I can remove this ugly callback with ease :D

function edit_callback($edit_user,$mail=''){
		$user = $this->ion_auth->user()->row();
		$mail = $user->email;
		return '<input type="text" id="email" name="email" value="'.$mail.'" disabled />';
	}

Amit Shah
  • profile picture
  • Member

Posted 13 February 2014 - 10:46 AM

Happy to help ...

 

Happy GCing :)