YUI3: Re-fire an event that I stopped from propagating? - yui3

I've got a form within a tabview with input fields. If the user changes the input fields, doesn't save, and then tries to change the tab I want to ask them if they want to save changes before the tab is changed. I'm preventing the tab-change from occurring using e.stopPropagation(). I then prompt the user to ask if they want to save their changes, discard them, or cancel. If the user chooses save or cancel I'd like to perform the operation and then change them over to the tab they requested.
Is there a way for me to re-fire the event? Or will I have to extract what tab they were requesting from the event and then manually change the active tab?

I would think that the best way to tackle this issue would be to select the tab programmatically instead of trying to "re-fire" the event somehow.
To select a tab programmatically with tabView, you need to use the selectChild(index) method.

Related

Subform validation (datasheet view)

I have a subform where the user can create rows. A new row is created by clicking a button on the main form, after which the user can set the other values. Two fields are required, and the user must not be allowed to leave them empty, even by closing the form. Instead, a MessageBox should alert the user and he should stay on the offending row, allowing him to set the required values.
This must work even if the user has not made any change to the fields.
I'm trying different events with message boxes to see if any of them fire, but none of them fire when I try to leave the fields empty, for example by changing row or closing the main form. I'm looking for some equivalent to "OnBlur" in Javascript.
I've tried BeforeUpdate and On Dirty, but both of them require a change. I've solved the one for when closing the form, using On Unload with the Cancel parameter.
If I understood it correctly you are trying to validate user's entry before inserting a new row. Did you try the event 'Before Insert' of the subform? Use Cancel = -1 to disallow inserting. That should work even if the user tries to close the main form.

Reset usercontrol placed on form

Probably simple question but couldn't find any working solution. I have User control on windows form. I would like on button click placed on user control to reload user control. By reload i mean to reset all its variables and show again. How to achieve that?
There is nothing that does that. You could dispose the existing control and create a new one but noone would do that. Basically, it's a manual process. If you want the control's fields reset to defaults then you need to write code to do that. You might declare a Reset method and put all the code in there if that's appropriate and then you can simply call that method from the form.

Need To Revert Multiple Controls Back To Previous Values

I have the following situation where I have multiple controls on a form. The user can select an Edit mode which allows them to modify the contents of the controls (textboxes, checkboxes, comboboxes, etc.) After editing has been made, the user can either select the Save or Cancel button.
Obviously clicking on save will save all changes to the database, however, if the user clicks on cancel, I want to 'somehow' revert all controls back to their previous state.
Currently, when the user clicks on cancel, the form turns off edit mode, but the controls remain with all the changes made until they reload the form.
Is there an easy way around this, or do I need to reload the entire form content from the database each time the user clicks on cancel?
Thanks in advance.
I'm just going to outline a possible solution here.
You could have a dictionary in your form in which you store the content of your controls whenever a user first modifies them, indexing them by the control name.
When the user starts modifying a control, you check if the control already exists in the dictionary. If it doesn't you add a new entry to the dictionary with the current value of teh control.
If the user cancels the editing process, you can loop through the dictionary, find each control in your form by its name (Form.Controls(ControlName) or something like that I think), set its value back to what it was and remove the entry from the dictionary.
It's not the most elegant solution as it will involve linking up all your controls to the TextChanged event or equivalent to capture their value when they are modified...
To avoid that, you could fill the dictionary right at the start when you load your form, after populating the values from the DB and then only set those controls' value back which have a different value when the user cancels.

Silverlight avoid requesting an event twice

I have a Control say for ex a Submit button if user clicks the button twice or more continuously then user receiving same message / same operation taking place twice or more.
I need to avoid this situation.
thanks for your inputs.
You need to detect the button click event either in the code behind of the view (or ViewModel if using the MVVM pattern) and disable the button. Now I take it that your submit button is firing off some kind of asynchronous operation. Once the asynchronous operation has successfully completed you will probably need to enable the button so that it is available again.
Shankar, if you want to avoid clicking on button, you should disable it. If you can give more details about what exactly you are trying to do, more details can be given.

How can I make a button not fire its action on click-through?

The Apple Human Interface Guidelines state that:
An item that provides click-through is one that a user can activate on an inactive window with one click, instead of clicking first to make the window active and then clicking the item. Click-through provides greater efficiency in performing such tasks as closing or resizing inactive windows, and copying or moving files. In many cases, however, click-through could confuse a user who clicks an item unintentionally.
and
Don’t provide click-through for an item or action that:
Is potentially harmful and does not allow the user to cancel it (for example, the Delete button in Mail)
Is difficult or impossible to cancel (such as the Send button in Mail)
Dismisses a dialog without telling the user what action was taken (for example, the Save button in a Save dialog that overwrites an existing file and automatically dismisses the dialog)
Removes the user from the current context (for example, selecting a new item in a Finder column can change the target of the Finder window)
What I want to do is that if the user clicks a specific button it will not send its message unless the window is active (for example, the delete message button in Mail). How can I achieve this? If I need to subclass NSButton that's fine.
Look at the NSView Documentation:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/occ/instm/NSView/acceptsFirstMouse:
You need to override acceptsFirstMouse to return TRUE to enable click through.
The default behaviour is not click-through:
The default implementation ignores theEvent and returns NO.
It's possible you have already overridden this method in your code, or in code you have based your code on. Try removing the implementation of acceptsFirstMouse in your code.