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

Reimplemented Form Validation #177

Merged
merged 4 commits into from
Jun 19, 2017
Merged

Conversation

romaninsh
Copy link
Member

@romaninsh romaninsh commented Jun 16, 2017

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.

  • form->setModel() will automatically save() data when submitted, because ... why not?
  • form->onSubmit() can execute error as before.
  • form->validate hook is no longer there, so we must review code to make sure it's not used in some field.

See if we can address the following issues with this PR:

@romaninsh romaninsh requested a review from DarkSide666 June 16, 2017 15:27

// look if name is unique
$c = clone $this;
$c->tryLoadBy('name', $this['name']);
Copy link
Member

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';
}

Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo - linking

@romaninsh
Copy link
Member Author

I'm leaving other fixes for later.

@romaninsh romaninsh merged commit 2950217 into develop Jun 19, 2017
@romaninsh romaninsh deleted the feature/add-form-validation branch November 13, 2017 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants