2

The CiviCRM EntityRef form element uses a Select2 select box to make lots of CiviCRM forms more awesome. A user can, for example, search for contacts to choose one. Great.

I am building an extension where I would like to take an EntityRef element from a core form and select a use javascript to select a specific entity (or multiple entities in the case of a multi-select). Is there a javascript function I can call in order to trigger such a selection (by passing in the ID of the entity, for example)?

1

1 Answer 1

1

According to this related question, it should be possible to do this via:

$('#id-of-select2').select2('val', 'value-to-select');

or, if you want to select multiple items in a multiselect:

$('#id-of-select2').select2('val', ['value-to-select', 'another-value']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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