Reputation: 6826
I have a complex situation involving several instances of a couple different modules.
For example, I have an input module, form module, and a formSelector module. Selecting a form on the formSelector should populate the form with the correct inputs.
Above the formSelector, I have another form with various inputs.
All the inputs are built out according to what is returned from the database.
Now, I tried using pub/sub to trigger an event to pass the form object from the formSelector to the form module. This works accept that the trigger isn't specific to the form module instance. It triggers the event for all of the forms on the page.
How can I trigger an event only for the specific form instance?
Example
Note: I made this up on the spot just for a reference for the structure. This code probably does not work. Also, I don't think the javascript is necessary to answer the question.
Input: Observes some data
<input data-bind="value: input.data" />
Form: List of Input Modules
<form>
<div data-bind="foreach: form.inputs">
<div data-bind="compose: { model: input.modelPath, activationData: input.activationData }"></div>
</div>
</form>
FormSelector: Select the desired form
//List of buttons to select the desired form
<div data-bind="foreach: forms">
<div data-bind="click: updateForm"></div>
</div>
//The desired Form (Module)
<div data-bind="compose: { model: form.modelPath, activationData: form.activationData }"></div>
Index.html
//Form Module
<div data-bind="compose: { model: mainForm.modelPath, activationData: mainForm.activationData }"></div>
//FormSelector Module
<div data-bind="compose: { model: formSelector.modelPath, activationData: formSelector.activationData }"></div>
Using the example, I want to trigger an event, inside updateForm
, which will only trigger for the form composed inside the FormSelector. The problem is, the app wide triggers will update the form above it (the mainForm
).
Upvotes: 0
Views: 378
Reputation: 625
Durandal has wired up events by default on the app class, so you can use the app.trigger and and app.on functions globally.
However, you can wire up your own object by using the Events.includeIn(obj) function.
For more information visit the documentation.
Upvotes: 0