0

In Webform 8 I am trying to figure out how to populate a text field with a value based on what is chosen on a drop down.

For example: Select Value are states If user selects Deleware then the value for the text field Ratified is equal to 1.

How can I achieve this in Webform 8x?

In Webform 7x I am able to do this with the Conditionals tab but can't seem to be able to figure out how to do this in Webform 8.

  • Populating a text field using conditions is not supported in 8.x because 8.x uses Drupal's #states API. – jrockowitz May 14 at 0:20
0

You have to use JS, go to settings - CSS/JS tab, write code in CUSTOM JAVASCRIPT textarea.

Some code for reference. I got a text input (id is edit-name), a select (id is edit-gender), the id you find enter 'F12' to see. ID is automatically generated by Webform. When I select male, the text input will appear male.

(function ($, Drupal) {'use strict';$(document).ready(function(){
  'use strict';
  var name = $("#edit-name");
  var gender = $("#edit-gender");
  var duty = $("#edit-duty-select"); 
  function ab() {if (gender.val()==='male'){name.val("male");} else {name.val("girl")}};  
  gender.change(ab);  // add a Listener to select
});  
})(jQuery, Drupal);

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.