I am trying to automatically select certain values in a multi-select form based on the user’s selection of other options in the multi-select field.
For example, if they select option A in the multi-select, I want to automatically also select options B and C for the user in the same multi-select field. I’m struggling to find a way to do this.
Unfortunately, this is not a supported feature and can only be done using custom code, can you please share the form and the logic of how the selections should be made? I can send you a code snippet that will help.
The last field “Which priorities…” is the field in question. We’d want all of the priorities under a chapter selected if the select the chapter. So, for example, if they select Chapter 1, it would also select priorities 1, 2 and 3 under chapter 1.
Let me know if you need anything else. Appreciate the example code snippet.
jQuery('#input_3_38').on( 'change', function( e, params ) {
if ( params && 'deselected' in params && params.deselected ) {
return;
}
var valueMap = { '9114':[ '9174', '9176', '9175' ] };
var clickedValue = e.target.value;
var allSelectedValues = [];
var map = Object.keys( valueMap ).includes( clickedValue ) ? valueMap[ clickedValue ] : false;
if ( map === false ) {
return;
}
allSelectedValues = allSelectedValues.concat( map );
allSelectedValues.push( clickedValue );
jQuery( this ).val( allSelectedValues ).trigger( 'chosen:updated' );
});
This should work for chapter one only, If that is what you need, I will just add the other values to the valueMap var and it should work for the other chapters as well.
Take a look at this article to know where to put this code snippet, if you need help with this as well just let me know!