Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide detailed validity information #46

Open
galzetta opened this issue Jun 3, 2020 · 1 comment
Open

Provide detailed validity information #46

galzetta opened this issue Jun 3, 2020 · 1 comment

Comments

@galzetta
Copy link

galzetta commented Jun 3, 2020

Currently the Checker only gives a true/false result. This is suboptimal in what is, I believe, one of the most common use cases for this library: validating the form of data for a user:

  • The user inserts tax code, name, surname etc
  • tries to save
  • you validate the CF & other data
  • it's wrong! good luck finding exactly where you made the typo

This library should provide an "extended validation" that tells you exactly which parts of the CF do not match.

For example a result value might be:

[
   "valid" => false,
   "errors" => [
       "name" => "'Antonio' does not match 'BCA'",
       "checksum" => "F is not the correct checksum letter for the given tax code"
    ]
]

This is just to give an idea of which information this library could easily provide and that I currently have to manually compute (making this library basically useless... If I have to compute by hand a more detailed validity check than what the library provides, why do I have to use this library in the first place?) in order to provide good feedback on the form.

Instead of complete error messages (which might be troublesome since that would mean troubles with translations) you could simply provide the information extracted from the tax code
So instead of "Antonio" does not match 'BCA'" you just return "name" => ["tax_code_portion" => 'BCA', "tax_code_without_omocodia_portion" => 'BCA']
Now I can easily display in the form, under the name "Antonio" a message like "This name does not match the name portion of the tax code (currently 'BCA').

@DavidePastore
Copy link
Owner

Hi @galzetta . Thanks for opening this issue. This is a useful use case. I think that the validation could have an advanced way to work, returning something like an array for every portion (name, surname, etc...), and each portion is made by an associative array with the section, value and expected_value keys. Here you have to be sure to return an array for the expected_value, because there are n possibilities based on the omocodia level.

I don't think this is really hard to implement but I need to find free time to do it, so in the meantime you could open a pull request for it.

@DavidePastore DavidePastore modified the milestones: 0.8.0, future-release Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants