Can parameters be injected from the template to a widget action?

Actually my problem could not be hacked the way presented above:

  • yes, the notification level was mutated but…
  • it was not saved. One would need to click elsewhere to save it with an other action.

By intensely searching random keywords on the github code database, I could find some structure like this one:
{{d-button action=(action "up" wc) ...}}.

With some testing, I came to the conclusion it works this way:

  • template:
    {{d-button action=(action "nameoftheaction" arg1 arg2) ...}}`.
    
  • JS:
    api.modifyClass("component:some-component", {
        actions: {
            nameoftheaction(arg1, arg2, argA, argB) {
                console.log(arg1);
                console.log(arg2);
                console.log(argA);
                console.log(argB);
            }
        }
    })
    

The first arguments arg1, arg2 of the methods are the one given by the template. The remaining arguments argA, argB… may be given by the specificity of the component (for exemple, the category-notifications-button will return an integer depending on the setting the user clicks on).

I am absolutely not sure what I write is correct but it may help someone asking the same question I did.

1 Like