⚠ 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

rule is_unique problem



kenshicu

kenshicu
  • profile picture
  • Member

Posted 29 July 2013 - 15:32 PM

$crud->set_rules('user', 'User','is_unique[tbl_user.user]');

the rule "is_unique", works ok, but when edit a record (user) with the GC, this rule is activated, this record being unique.
the rule "is_unique", should only be activated by insert in GC in this case.

how to solve this problem?, I need the user editbox, is unique.

 

and

 

how I create my own rule?

 


sorry my bad english


davidoster

davidoster
  • profile picture
  • Member

Posted 29 July 2013 - 21:54 PM

Hello [member=kenshicu].

It is normal behaviour while in edit mode to have the rule activated.

If you feel that this is not what you need to have as a validation then use the callbacks as here.


kenshicu

kenshicu
  • profile picture
  • Member

Posted 30 July 2013 - 12:54 PM

ok, but as I do this of Codeigniter in groceryCRUD:

$this->form_validation->set_rules('username', 'Username', 'callback_username_check');

public function username_check($str)
	{
		if ($str == 'test')
		{
			$this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}

In GroceryCRUD would look like?

$crud->set_rules('user', 'User','callback_username_check');   

 

To create my own rules.


davidoster

davidoster
  • profile picture
  • Member

Posted 30 July 2013 - 14:07 PM

Yes. If you read on the set_rules page, it says:

"Set Validation Rules works with the exact same way as Codeigniter set_rules"


kenshicu

kenshicu
  • profile picture
  • Member

Posted 30 July 2013 - 14:37 PM

Yes, I read it, but the rules with callback not work in GroceryCRUD

if anyone has any example would appreciate
.


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 09 April 2014 - 20:14 PM

well brother u can check the solution in here