djit.layout.Tabcontainer - click-based event is fired two times - dojo

I want to add listeners on selection event, but implementation via code below fired event two times. Only javascript core onClick event is fired correctly one time.
dojo.connect(myTabCont, "onButtonClicked", function(tabList){
console.log(tablist);
});
dojo.connect(myTabCont, "selectChild", function(tabList){
console.log(tablist);
});
//work fine - one click one fire
dojo.connect(myTabCont, "onClick", function(event){
console.log(event);
});
Is there is feature or bug? Or can you help how to workaround these funcionality or way how to broke this feature || bug.
Thanks

Sounds like a bug. selectChild() is idempotent so there's no harm in calling it twice (except for people like you that are connecting to it :-) ), so that's why we didn't notice the problem.
You could monitor the [widgetId]-selectChild topic, which will only fire once, or just ignore myTC.selectChild(foo) calls when foo == myTC.selectedChildWidget.

You could monitor the
[widgetId]-selectChild topic, which
will only fire once, or just ignore
myTC.selectChild(foo) calls when foo
== myTC.selectedChildWidget.
Equals check between old-selection and new-selection in Stack_Container.selectChild method is ok!
There is no bug. Registered "selectChild" is called two times and this is correct behaviour. First calling of "selectChild" is event fired by user, the second calling is programmaticlly when StackContainer check if old-selection NOT equals new-selection and fire onclick on tabItem explicitly.

Related

see the list of event listeners currently attached

I want to check the list of event listeners that are added. For example, I used the code cy.on('pan zoom resize', update); and added function called update in for loop. I do this many times. I also call cy.off('pan zoom resize', update); to remove the event listeners but I want to be sure about it.
The only think I can think of is using console.log but this method might not be helpful.
I also think that in some places people forgot to remove the event listeners and just always added. With too many repetitions this might cause problems.
There is a data field in the private cytoscape object called listeners. You can see that if you:
console.log() the cy object,
navigate to _private,
then open the emitter object
and lastly go to listeners
This is the array listing all the default and user defined event listeners with some metadata like the event, type and scope of the listener.
You can access this in your code by simply calling
cy.emitter().listeners
The question now is, why do you need this information in the first place? Normally, you should be just fine if you call cy.off('eventXY', ...) before using any cy.on('eventXY', ...). Are you sure you need this for your application to work? Maybe elaborate more on the core problem (why you want these information in the first place).
Thanks and have a great day!

How to suspend / resume the events of a particular component in Titanium?

Can anyone please let me know how to suspend/resume the events of a particular component. For example
textfieldObj.suspendEvents();
This will suspend all the events of that particular component means which will not fire any event listener if action happens also.
textfieldObj.resumeEvents();
All the events of that component will be fired if action performs.
Is there any thing like this in titanium?
Thanks in Advance,
Swathi.
In Titanium you can add and remove eventListeners. This goes for all Titanium types which are capable of firing events.
If you want to receive all events of a type (e.g. click) use
textfieldObj.addEventListener('click', function(e){
// perform your action
});
If you don't want to receive anymore events use
textfieldObj.removeEventListener('click', function(e){
// perform your action
});
You can read about it in the documentation.
If that doesnt work, this is Javascript and you can apply Backbone Events to the objects - http://backbonejs.org/#Events

Cancelling the onChange event of a dijit/form/FilteringSelect

I need to be able cancel the onChange when a user tries to change value in FilteringSelect depending on if another action has made the information dirty or not.
I have tried to use the FilteringSelect's undo() method, but it's not working. I've tried aspect.before for the onChange event, but that seems to be hooked too late since the control has already got the new value. I tried to hook to the method that calls onChange, but have not been able to find that method.
How do I best accomplish this?
Once the value is set to this widget, the value of "_lastDisplayedValue" also updates. So, undo is not apt for this case.
If the onChange event handler on this widget need to be detached, based on some conditions, "_onChangeActive" private flag can be made use. This is not supposed to be used by programmers explicitly and is for internal purpose of the widget. But, for this case, this can give a hack.
Set _onChangeActive=false, and the handler will be detached. But do not forget to reset it to true again, else, onChange function does not work, if this is set to false.
e.g:
var widget = dijit.byId('widgetId');
widget.set('_onChangeActive',false);
widget.set('value',newValue); //onChange handler function does not run
//not just programmatic,
//even if user tries to select, when onChangeActive=false this works
widget.set('_onChangeActive',true);
//now the onChange is resumed back

Can SpineJS block the UI when updating?

One of the stated SpineJS goals is to make the entire UI non-blocking (i.e. display the change to the user, even though it might have not been updated successfully on the server side yet).
Can it be used in a standard "blocking" manner?
Yes it can. Look here under "callbacks":
http://spinejs.com/docs/ajax
You can basically block the UI at any point, and I do it for things that just can't be deferred to the server. Note that I don't even use the ajaxSucess() event, but just custom bindings for events. Here is an example use case in meta programming:
Bind 'clickHandlerFinish' event to clickHandlerFinishWork()
Bind 'click' event on button a to clickHandler()
User clicks on button a
clickHandler() gets fired
clickHandler disables the button and blocks the UI
clickHandler makes an AJAX call to the server to do work
(Remember UI is still blocked)
AJAX call finally returns, and fires the clickHandlerFinish() callback
clickHandlerFinish() unblocks the UI, re-enables the button, and presents the new changes
I've used this successfully on a few instances. Works great for me!

Using Dojo to reenable a submit button when a form is edited

I'm trying to build a web app using Dojo. I have a form that posts data via Dojo's xhrPost capabilities to a server side program that saves changes made on the form whenever the user hits the "save" button. What I would like to do is disable the save button after a successful save until the next time something is changed in any of the form's fields to avoid repeated attempts to save an unchanged document.
I tried having Dojo's event watching functionality watch for changes, but have not been successful. The event intended to trigger reenabling the save button never does anything. Here is what I tried:
eventWatching.push(dojo.connect(dijit.byId('editForm'), 'onChange', function() { dijit.byId('saveButton').set('disabled', false); }));
Using onKeyPress instead of onChange seemed promising, but that did not (obviously) reenable the button when the form was edited using the mouse alone.
Prior to 1.6, I don't think dijit.form.Form connects its children's onChange to its own, which is likely why your onChange idea didn't work.
In Dojo 1.6, what you're asking for is easily possible by taking advantage of the fact that widgets now inherit dojo.Stateful functionality:
form.watch('value', function(property, oldvalue, newvalue) {
/* ... */
});
In 1.5 or lower this might take some work; can't think of an easy way off the top of my head but maybe someone else has an idea or one will hit me later.
You can find the code responsible for hooking up the onChange and value-watching functionality in 1.6 here: https://github.com/dojo/dijit/blob/master/form/_FormMixin.js#L396-429
If the newvalue is emptyString the form is valid.
frm1.watch('state',function(property, oldvalue, newvalue) {
console.log(newvalue)
})