atk4 / ui

Robust and easy to use PHP Framework for Web Apps
https://atk4-ui.readthedocs.io
MIT License
440 stars 104 forks source link

Required fields are not checked on final step of Wizard #2156

Closed pootedesu closed 3 months ago

pootedesu commented 5 months ago

Expected Behavior Clicking "Finish" on the final page of a Wizard will check all required fields and prompt for any blank fields before moving forward.

Actual Behavior Clicking "Finish" displays the finish screen and ignores required fields.

<?php

declare(strict_types=1);

namespace Atk4\Ui\Demos;

use Atk4\Ui\Form;
use Atk4\Ui\Header;
use Atk4\Ui\Wizard;

/** @var App $app */
require_once __DIR__ . '/../init-app.php';

$wizard = Wizard::addTo($app);

$stepFx = static function (Wizard $wizard) {
    $form = Form::addTo($wizard);
    $form->addControl('city', [], ['required' => true]);
    $form->onSubmit(static function (Form $form) use ($wizard) {
        return $wizard->jsNext();
    });
};
$wizard->addStep(['Step 1'], $stepFx);
$wizard->addStep(['Step 2'], $stepFx);

$wizard->addFinish(static function (Wizard $wizard) {
    Header::addTo($wizard, ['Wizard completed']);
});
mvorisek commented 5 months ago

The bug is here: https://github.com/atk4/ui/blob/ca975df74c/src/Wizard.php#L145 - form is submitted only using the next button but not the finish button. Fix is easy, but Behat tests need to be coded...

mvorisek commented 3 months ago

Thank you!