Hi web-johnny,
I’ve just worked on a simple users table and ran into an issue with the is_unique validation.
Osci wrote a nice My_Form_validation to solve the is_unique problem when editing: http://ellislab.com/forums/viewthread/192334/
Part of the controller:
$state = $this->grocery_crud->getState();
$state_info = $this->grocery_crud->getStateInfo();
if( $state == 'insert_validation' )
{
$this->grocery_crud->set_rules('password', 'Password', 'trim|required');
$this->grocery_crud->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[clients.email]');
}
if( $state == 'update_validation' )
{
$this->grocery_crud->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[clients.email.id.'.$state_info->primary_key.']');
}Now I had to change two things in the grocery_CRUD library to make this happen.
1) Change the getStatInfo() to return a primary_key as it was emtpy on “update_validation”.
2) Change the is_unique method into that of the one Osci wrote.
Question: Is there a better way to handle unique fields? And is there a way to extend the grocery_CRUD library?