0

Is there a way with Drupal 8 Webform UI to set the default value of a text field as the value of an earlier text field in the same form, and update via Ajax?

example:

user_name:
     '#type': textfield
     '#title': 'User Name'

nick_name:
    '#type': textfield
    '#title': 'Nick Name'
    '#default_value': '[webform_submission:values:user_name]'
    '#ajax': true

But the default value does not render the token and just prints plain text.

Any help is much appreciated, thanks.

1

The short answer is 'No' to using tokens to sync two element values, unless the two elements are on different pages. The simplest solution is a write a little JavaScript to sync the nickname with the username.

You can search for examples of sync'ing two input fields.

The Webform module's Options admin widget uses a little JS to sync an option's value with the option's text. @see webform.element.options.admin.js

|improve this answer|||||
  • Thanks for the answer, I was able to add in some JS that changes the value of the desired field based on input from another field - if it is empty. – Joshua McCormack Feb 6 '19 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.