Question

I've created a webform with a text field which has cardinality of 1 and there are submissions made for that webform. I now want to change the cardinality to unlimited, but I can't do it in the webform UI. I'm not able to change the value.

This is the tootltip shown when I hover over the Allowed number of values field in webform form element settings Allowed number of values field.

There is data for this element in the database. This setting can no longer be changed.

screenshot

screenshot

I tried to programmatically change it using hook_form_alter().

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'form_id') {
    $form['field_name']['cardinality']['#default_value'] = FIELD_CARDINALITY_UNLIMITED;
  }
}

That didn't work either. Where am I going wrong?

Was it helpful?

Solution

It is possible to change an element with a singular cardinality via the YAML source without any data loss. You would definitely lose data going from multiple cardinality to singular.

In the YAML source, add the '#multiple': true property to the element.

name:
  '#type': textfield
  '#title': 'Name'
  '#multiple': true
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top