Event handling between two custom controls - event-handling

I have two custom controls. Control A attaches an event handler on Control B by calling
b.attachEventName( function(event, data){ ... })
after instantiating b.
Control B reacts on a click and fires the relevant event by doing something like this:
this.fireEventName( { key: value } );
I observe that I don't have access to the object, I gave as parameter in the firing of the event in the attached function in control A. How can I get access to that object?
PS: For clarification: I want to reuse Control B, and different controls, which use B might want to attach different functions for a specific event.
Thanks,
Christian

The problem is with syntax you are using to attach event to the control.
If you want to pass an object along with the event object when firing the event, code would be:
b.attachEventName(oData, function(oEvent){
// your stuff
});

This should do:
b.attachEventName(function(event, data) {
var sKey = event.getParameter("key")
});
The second parameter data in this function is the data that you potentialy passed when registering the event listener as described above by Dopedev.
BR
Chris

Related

Get properties from other class (d3)

Hey im using the d3 plugin to work with the Collapse Tree. This is my example: http://bl.ocks.org/mbostock/4339083
Now i created 2 Widgets which are in 2 different classes. One for the tree and one for a control element. Now i want to change the properties of clicked nodes with my control element widget. So I need to get the Data(Object) from the clicked node in my other class. After I need to manipulate that data using my control widget.
"Dojo on" / "Dojo connect" are just for DOM interactions right?.
I want to communicate between the javascript classes.
Here is my onclick function for clicking the nodes:
.on("click", function (d) {
toggle(d);
update(d)
})
You can create a custom event in the tree class and handle it from the other class. First, define an event handler for the onClick event on the tree node.
onClick: function(evt) {
// here comes your code
// when you're finished, fire a custom event
this.onNodeClicked(params);
},
onNodeClicked: function(params) {}
In the other class, listen for the custom event. Here I assume you create the tree widget from there. Otherwise, you can pass a reference to your tree object.
var tree = new MyTree();
dojo.on(tree, "onNodeClicked", this._handleOnNodeClicked);
Hope this helps.

Kendo MVVM data binding with a custom Kendo widget

I created a custom Kendo widget that is will be a composite control made up of a few other widgets. I have everything working except MVVM-enabling it, specifically I can't get the view model's value to update whenever the control is updated. However, if I update the view model directly, the control's value get's updated, just not the other way around. It needs to be two-way. I put together an example of this issue:
http://jsbin.com/obejey/3/
Any help would be hugely appreciated!!
You are SO close! :) All you are missing is to trigger a change event when your value changes. To do this, simply monitor the change event of your ComboBox and when it changes, trigger a change of your custom widget.
Add this bit of code:
_initAutoComplete: function () {
var that = this;
that.select.kendoComboBox({
...,
// ADDED CODE...
change: function () {
that.trigger("change", {field: "value"});
}
});
},

Event.add for keypress does not work?

We are trying to use tinyMCE for one of our applications. We would like to attach some event handling to particular elements within tinyMCE. We've tried doing it using
Event.add(element, 'keypress', getTag);
Where element is the HTML element we are trying to attach the event to and getTag is the function we'd like called when the keypress event is fired. The particular element we are trying to attach to is a span element with some text in it. We'd like to capture when particular key combinations are entered(like ctrl - F10) between the span tags and popup a menu with options.
The options in the menu will vary depending on the particular span elements the combination is entered in. That's why we want to attach to particular elements instead of globally attaching to all span elements in the document(within tinyMCE). i.e The getTag function will behave differently, using closures, depending on where the combinations are entered.
The problem is when we attach to the particular elements and test them nothing happens for any 'keypress' events. If we try to attach to the span elements using a 'click' event everything works as expected. Once we revert back to using 'keypress' nothing happens again.
Using the debugging tools I've verified a couple of things. The event listeners are attached to the elements. It seems tinyMCE creates a toplevel keypress and click(along with others) to the document within tinyMCE. I'm guessing this is how Editor.onKeyPress().add() like functions work. When I debug the working scenorio using click I can see where the event is fired for both the document and span elements. While debugging the keypress event I only see the event fired for the document element, not the span element. I'm thinking that tinyMCE is suppressing the event, but I can't figure out how, and what needs to be done to stop it.
Use this handler eigther in one of you own plugins or using the tinymce config param setup
ed.onKeyDown.add(function onkeydown(ed, evt) {
var is_in_span = ed.selection.getNode().nodeName == 'SPAN';
// check for caret in SPAN and F10-Key
if (is_in_span && evt.keyCode == '121'){ // you may add other keyCodes here
// do whatever you like here
...
}
});

How to listen to modifications of the contents of an SWT List?

I tried using a listener for SWT.Modify event. This works for Text but seems not to work for List. That is, the following does not work:
myList = new List(listComp, SWT.MULTI|SWT.BORDER|SWT.V_SCROLL);
myList.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event e) {
System.out.println("My list modified");
dirty=true;
}
});
Thanks for your help.
Listen to the SWT.Selection event instead of SWT.Modify.
Consider also to use a ListViewer instead of a List, which has addSelectionChangedListener() and addPostSelectionChangedListener() methods (the later is used be notified when user 'stops' on an item when navigating in the list with keyboard, instead of notifying on each item).
You should register listeners to your model which is visualized with the list and listen for changes there instead of the widget.
Why don't you create your own custom list (check e.g. http://www.snip2code.com/Snippet/11489/Custom-SWT-List-Box) and directly manage events from within your class?

Get Value on a Window with GridPanel using ExtJS

I have a situation here: I have a form field with trigger xtype, what I want to happen on my trigger function is to open a window with a list or grid of data in it. I want to get the value of those data and assign it as the value of my form field with trigger. Can anyone help me solve this problem. Thank you very much.
You have multiple solutions for this.
You can make use Saki's simple message bus to do the communication between extjs components.
You can create an custom event for your trigger field. When user selects a record in your window, fire the event with the selected record.
Inside your onTriggerClick :
Display your window with grid / view for user selection
Inside your Window (on some submit button):
onSubmitClick: function(){
// Get the selected record & fire event
var selected = grid.getSelectionModel().getSelected();
triggerFieldObject.fireEvent('recordSelect',selected);
}
Inside your event processing (Will be on TriggerField):
onRecordSelect: function(record) {
// Now you have access to the selected record.. process it,
// Set the trigger field value etc
this.setValue('Your Value for Trigger Field');
}
Note: This is a skeleton code and not a complete solution. You will need to add your code according to your requirements.