isClicked example

public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\SubmitType';

    public function testCreateSubmitButtonInstances()
    {
        $this->assertInstanceOf(SubmitButton::class$this->factory->create(static::TESTED_TYPE));
    }

    public function testNotClickedByDefault()
    {
        $button = $this->factory->create(static::TESTED_TYPE);

        $this->assertFalse($button->isClicked());
    }

    public function testNotClickedIfSubmittedWithNull()
    {
        $button = $this->factory->create(static::TESTED_TYPE);
        $button->submit(null);

        $this->assertFalse($button->isClicked());
    }

    public function testClickedIfSubmittedWithEmptyString()
    {
$form = $this->createForm()
            ->add($this->createForm('text', false))
            ->add($submit)
        ;

        $form->submit([
            'text' => '',
            'submit' => '',
        ]);

        $this->assertTrue($submit->isDisabled());
        $this->assertFalse($submit->isClicked());
        $this->assertFalse($submit->isSubmitted());
    }

    public function testArrayTransformationFailureOnSubmit()
    {
        $this->form->add($this->getBuilder('foo')->setCompound(false)->getForm());
        $this->form->add($this->getBuilder('bar', null, ['multiple' => false])->setCompound(false)->getForm());

        $this->form->submit([
            'foo' => ['foo'],
            'bar' => ['bar'],
        ]);

class SubmitType extends AbstractType implements SubmitButtonTypeInterface
{
    /** * @return void */
    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $view->vars['clicked'] = $form->isClicked();

        if (!$options['validate']) {
            $view->vars['attr']['formnovalidate'] = true;
        }
    }

    /** * @return void */
    public function configureOptions(OptionsResolver $resolver)
    {
        
foreach ($this->children as $name => $child) {
                    $isSubmitted = \array_key_exists($name$submittedData);

                    if ($isSubmitted || $clearMissing) {
                        $child->submit($isSubmitted ? $submittedData[$name] : null, $clearMissing);
                        unset($submittedData[$name]);

                        if (null !== $this->clickedButton) {
                            continue;
                        }

                        if ($child instanceof ClickableInterface && $child->isClicked()) {
                            $this->clickedButton = $child;

                            continue;
                        }

                        if (method_exists($child, 'getClickedButton') && null !== $child->getClickedButton()) {
                            $this->clickedButton = $child->getClickedButton();
                        }
                    }
                }

                
Home | Imprint | This part of the site doesn't use cookies.