-
Notifications
You must be signed in to change notification settings - Fork 107
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
Reimplemented Form Validation #177
Conversation
demos/database.php
Outdated
|
||
// look if name is unique | ||
$c = clone $this; | ||
$c->tryLoadBy('name', $this['name']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work always. Sometimes tryLoadBy will load current record first and not even check if there are more records. So it's better to do this with conditions something like:
$c = clone $this;
$c->addCondition('name', $this['name']);
$c->addCondition($c->id_field, '<>', $this->id);
$c->tryLoadAny();
if ($c->loaded()) {
$errors['name'] = 'Country name must be unique';
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this still is not 100% safe way to check name uniqueness.
what is name already is not unique in database?
@@ -53,26 +54,59 @@ To create a form you need the following code:: | |||
$form = new \atk4\ui\Form(); | |||
$form->addField('email'); | |||
|
|||
$layout->add($form); | |||
$app->layout->add($form); | |||
|
|||
The first line creates a "Form" object that is assigned to variable `$f`. Next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... variable $form not $f
docs/form.rst
Outdated
Integrating Form with a Model | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
As you work on your application, in most cases you will be linknig Form with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo - linking
I'm leaving other fixes for later. |
New validation now is in line with the Agile Data 1.2 release. Define validations at the model level for multiple fields!
Several other validation ways are depreciated and some major changes which is why we'll pack this into UI 1.2.
See if we can address the following issues with this PR: