Ticket #461 (closed Feature Request: wontfix)

Opened 7 months ago

Last modified 3 months ago

Add NOT to the Validation rules or callbacks

Reported by: sasan Owned by: - No owner -
Priority: minor Milestone: 2.2
Component: Libraries:Validation Version: SVN HEAD
Keywords: Cc:

Description

Add ! to the validation rules or at least callbacks. So that you can have a rule by which you will be able to have the opposite result.

Change History

Changed 7 months ago by allain

Usage might be: $validation->add_rules('username', '!username_exists', '!email');

It's a pretty specific use case, but I see value in it.

Though this is unnecessary, developers can always code their own callbacks that checks for the opposite of a builtin, it'd make the intent clearer with less developer code.

Changed 7 months ago by sasan

In this case I meant to use same callbacks in different cases. For example 'username_exist' and '!username_exist'

Changed 7 months ago by allain

Of course. All I was agreeing with you. Instead of having two callbacks, you could use one.

I like it.

Changed 7 months ago by allain

  • owner changed from Shadowhand to - No owner -
  • component changed from Core to Libraries:Validation

Changed 7 months ago by spirit

I'm not sure that this feature is necessary. It will bring some problem for example in forms validation error messages: only one method so only one message for two different tests.

Moreover:

function username_exists() {
 // Code here
}
function username_not_exists() {
 return !$this->username_exists();
}
$validation->add_rules('username', 'username_exists');
$validation->add_rules('username1', 'username_not_exists');

is not really heavy.

Changed 6 months ago by PugFish

  • milestone changed from 2.1.2 to 2.2

Changed 3 months ago by Shadowhand

  • status changed from new to closed
  • resolution set to wontfix

I agree with spirit, this adds too much complexity to error reporting, and the use case is rather small, imo.

Note: See TracTickets for help on using tickets.