Skip to content

Unicorn.call with arrays for select2 multiple #343

Answered by vaughnd
vaughnd asked this question in Q&A
Discussion options

You must be logged in to vote

For now I've worked around it with varargs in the Python method and using JS spread:
onchange="console.log($(this).val()); Unicorn.call('select2_country', 'select_country', ...$(this).val());"

Doesn't look like the Unicorn.call function supports anything more than basic string interpolation.

/**
 * Call an action on the specified component.
 */
export function call(componentNameOrKey, methodName, ...args) {
  const component = getComponent(componentNameOrKey);
  let argString = "";

  args.forEach((arg) => {
    if (typeof arg !== "undefined") {
      if (typeof arg === "string") {
        argString = `${argString}'${arg}', `;
      } else {
        argString = `${argString}${arg}, `;
   …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@adamghill
Comment options

Answer selected by adamghill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants