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

Container::getValues() when !isValid #266

Closed
redeyecz opened this issue Feb 5, 2021 · 0 comments
Closed

Container::getValues() when !isValid #266

redeyecz opened this issue Feb 5, 2021 · 0 comments

Comments

@redeyecz
Copy link

redeyecz commented Feb 5, 2021

Version: 3.1.1

Bug Description

When validation of form/container fails, any getValues() call after it (in onError / onValidate handlers) causes User warning

Steps To Reproduce

Presenter:

public function createComponentBug()
  {
      $form = new Form();
      $form->addText('test');
      $form->addSubmit('submit');

      $form->onValidate[] = [$this, 'onValidate'];
      $form->onValidate[] = [$this, 'onValidate2'];
      return $form;
  }

  public function onValidate(Form  $form) {
      dump('validation fail');
      $form->addError('Failed');
  }
  public function onValidate2(Form  $form) {
      dump('second validation');
      dump($form->isValid());
      dump($form->getValues());
  }

Latte:

{block content}
   {control bug}
{/block}

Outputs:

dump('validation fail') 📍'validation fail'
dump('second validation') 📍'second validation'
dump($form->isValid()) 📍false

... and triggers the warning

Screenshot_2

Expected Behavior

When validating, we usually append additional info from submitted values why the form was invalid, this makes it really awkward to use with custom validators (or when skipping netteForms.js validation for complex nested controls). I'd not expect it to throw any warnings when using getValues() with invalid form/container

Additionally, the same error occurs when the validator has second argument in it's signature!

Possible Solution

Just ... remove it? What's the point?

if ($form && $form->isSubmitted() && !$form->isValid()) {
trigger_error(__METHOD__ . '() invoked but the form is not valid.', E_USER_WARNING);
}

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

No branches or pull requests

1 participant