What are the Slack Archives?

Itโ€™s a history of our time together in the Slack Community! Thereโ€™s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you wonโ€™t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hi everyone! I'm trying to implement multiple payment options. I now have AfterPay and Klarna. When

U021QH3GDGV
U021QH3GDGV Posts: 17 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet
edited August 2022 in Help

Hi everyone! I'm trying to implement multiple payment options. I now have AfterPay and Klarna. When i'm in checkout process on payment step i have

<

ul> element with list items in it. (Picture 1). When i select on let's say afterPay and press button to go to "Summary" step. Both of Sub Forms get validated even though i haven't selected one al all. Did anyone encounter problem like this ? How can i disable validation of certain subform if it has not been selected.

Comments

  • U01K43ADW5N
    U01K43ADW5N Posts: 69 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    Did you end up with a solution?

  • U021QH3GDGV
    U021QH3GDGV Posts: 17 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    No i did not.

  • U01K43ADW5N
    U01K43ADW5N Posts: 69 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    I got one for you.
    You have to add a callback constraint for the field you want to validate and check if the payment selection is the same as the subform name.

    field example:

    /**
         * @param \Symfony\Component\Form\FormBuilderInterface $builder
         * @param array $options
         *
         * @return $this
         */
        private function addPhoneField(FormBuilderInterface $builder, array $options)
        {
            $builder->add(static::FIELD_PHONE, TelType::class, [
                'label' => 'amazon.pay.phone.required',
                'required' => true,
                'trim' => true,
                'data' => $options[SubFormInterface::OPTIONS_FIELD_NAME][static::FIELD_PHONE] ?? null,
                'constraints' => [
                    new Callback([
                        'callback' => function ($phone, ExecutionContextInterface $context) {
                            /** @var Form $rootForm */
                            $rootForm = $context->getRoot();
                            if ($rootForm->get('paymentSelection')->getData() !== $this->getName()) {
                                return;
                            }
    
                            if ($phone === null || $phone === '') {
                                $context->buildViolation(static::VALIDATION_NOT_BLANK_MESSAGE)->addViolation();
                            }
                        },
                    ]),
                ]
            ]);
    
            return $this;
        }
    
  • U021QH3GDGV
    U021QH3GDGV Posts: 17 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    thanks. i'll try it out.