AjaxAddRemoveElements not working if form contain a required select

Created on 13 May 2022, over 2 years ago
Updated 19 February 2023, over 1 year ago

Problem/Motivation

I tested the Form API AjaxAddRemoveElements example.

The form works fine. However, I noticed a malfunction if we add a select or a checkbox with a required in this form.

Steps to reproduce

To reproduce the problem, just add this element in buildForm()

$form['test'] = [
    '#type' => 'select',
     '#required' => TRUE,
     '#options' => [
         '1' => 'Lorem',
         '2' => 'Ipsum'
     ],
];

The add field feature no longer works.

Proposed resolution

So far, I don't see what is causing this problem.

Maybe someone can improve the example to allow it to be integrated into a form where we have a select with a required.

🐛 Bug report
Status

Postponed: needs info

Version

4.0

Component

Form Example

Created by

🇫🇷France sébastien-fr Nantes - France

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇳China jungle Chongqing, China

    Add '#default_value' => '1', to your form element to see if it works for you? And please try it with the latest dev branch 4.0.x or the latest release v4.0.0

    $form['test'] = [
        '#type' => 'select',
         '#required' => TRUE,
         '#default_value' => '1',
         '#options' => [
             '1' => 'Lorem',
             '2' => 'Ipsum'
         ],
    ];
    

    Thanks!

Production build 0.71.5 2024