References to other tokens in event functions
Closed this issue · 2 comments
Something along the lines of the following scenario should be possible:
<input type="text" id="searchField" />
<button m-click="search(#searchField[value])">Search</button>
Where we basically send the value of searchField along with the search event. Don't take the above as an explicit rule, it's just an example of a possible solution. We probably want to prevent sending full objects to the backend as much as possible. This would be for all event functions, not just for m-click.
@kevindeyne
I think this should work:
<div>
<input id="_first" style="width:80px" value="[$first]"/>
<input id="_second" style="width:80px" value="[$second]"/>
<!-- should resolve in a call to calc("1", "2", "add") -->
<button id="btn_sum" m-click="calc(#_first.value, #_second.value, 'add')">SUM</button>
<!-- should resolve in a call to calc("1", "2", "minus") -->
<button id="btn_min" m-click="calc(#_first.value, #_second.value, this.name)" name='minus'>SUBTRACT</button>
<!-- should resolve in a call to calc("1", "2", "multiply") -->
<button id="btn_mul" m-click="calc(#_first.value, #_second.value, this.operation)" operation="multiply">MULTIPLY</button>
<br>
<!-- should resolve in a call to calc("40", "2", "add") -->
<button id="btn_42a" m-click="calc(this.first, this.second, this.operation)" first="40" second="2" operation="add">40 + 2</button>
<!-- should resolve in a call to calc("21", "2", "multiply") -->
<button id="btn_42m" m-click="calc(this.value, this.name, this.operation)" value="21" name="2" operation="multiply">21 * 2</button>
</div>
ref: work in progress feature/event-functions
I am ok with these being passed as String, as that is how their value exists in HTML. If you want to use it as a Date, etc - it should be trivial for people to decide themselves to parse it. Making an assumption about how to parse such a value could cause too many issues.