I'm currently trying to toggle a 'Locked' element so that it is no longer locked once a check is performed. In the properties of the button, I have set the default value to be 'Locked' so that the user cannot use it's functionality.
When another button is clicked, my macro runs a process and if the process returns true then then the other 'Locked' button should be 'Unlocked' and a textbox containing a name should be 'Locked' to prevent alteration. The processing is done in a module called 'PNC_Module2' and the form that I wish to lock and unlock elements on is called 'folder_creator_window'.
I'm currently using the following lines to try and achieve the 'Lock and Unlock' but it doesn't seem to be doing anything:
'This is supposed to unlock the create_folders_button
folder_creator_window.create_folders_button.Locked = False
'This is supposed to lock the p_name_textbox textbox
folder_creator_window.p_name_textbox.Locked = True
I haven't included the rest of the code as it has no real baring on what occurs here.
Seeing the rest of your code may reveal the problem as your syntax looks ok
But on your quest as asked The normal method of toggling is to reverse the current condition using NOT. ie to toggle Locked on CommandButton1 on UserForm1 you would use:
UserForm1.CommandButton1.Locked = Not UserForm1.CommandButton1.Locked
Related
Short overview of my issue: I have a large form with several fields, one of them is a xe:djFilteringSelect and one a xp:combobox. The xp:combobox is computet depending on the value selected in the filtering select. Now my customers want that if they change the value of the filtering select of a already saved docoument they should be prompted with a warning. So i want to add a confirm message to the onChange event of the djfilteringselect to cancel it's SSJS code wich changes the combobox.
Prompting the user with a confirm ("change value?...") box is no big deal but reseting the value back (on ClientSide) if the users selects "no" gives me a lot of trouble.
What i have already tryed:
If i use a simple confirm action all further onChange actions get canceled but the djFilteringSelect field keeps it's user selected value. So if i fire a partial refresh on the filtering select the original value form the document is displayed but i don't know where to add it because there is no onCancel or did i miss something here?
I also tried it from the CSJS with window.confirm and XSP.confirm and reset the value manual with a XSP.partialrefreshGet() if the user selects 'no' but in this case the partial refresh does not work:
if(!XSP.confirm("execute?")){
XSP.partialRefreshGet("#{id:repeat1}",{
onStart: function () {console.log("start");},
onComplete: function () {console.log("finish");},
onError: function () {console.log("error");}
});
return false;
}
If i move the partial refresh to a function and call it from e.g. firebug it works fine but if i call it inside the if(confirm){} it does nothing at all. The return false does work the SSJS does not get executed. The value in the document is not changed (as intended), but the djFilteringSelect keeps the selected value on the ClientSide.
I also tried Mark Leusink´s dojo-style Confirm but same Problem with the partial refresh here.
If i set the value back manual instead of using a partial refresh with dijit.byId(item).setValue it will resoult in another onChange Event... loop. Update: If i use dijit.byId(item).set("value",newVal,false) the onChange does not fire direct it changes the value as intended but then the onChange fires when the filtering select looses ist ??focus!?!? ...
So my questions:
Is there a ways to execute any Code after the confirm action if the user selects "no".
Why is the partial refresh in my CSJS not working (i dont see any traffic in firebug and i dont get any errors not even the onError of the refresh gets fired).
Does anyone know a different approach to my problem?
update:
My current 'solution' is to use window.location.reload() instead of the XSP.partialRefresh to reload the site. But this solution does not really satisfy me, because in IE the whole page is flickering.. in firfox i can live with it.
I have a textbox that I would like to prevent the user from entering any letters in. They need to be able to enter numbers.
The textbox has an onkeypressed event already set, and I'm adding logic so that if the user enters a letter, nothing is shown.
Regardless of what I do (cancelbubble, stop propogation, return false), the letter is still getting entered in the text box. I've watched the debugger go over these and still the letter is being entered, its like it is taking place after the fact of the event.
The event handler hook you are looking for is onkeydown:
yourInput.onkeydown = function(e){
var char = String.fromCharCode(e.which); // get the char
return /[0-9]/.test(char); //assert it's a number
}
working demo
Returning false from an event handler attached directly (rather than attachEvent) cancels the event.
Actually once I got home to test onkeydown was doing the same thing, when I edited what was in the text box, it would still add the non-numeric character at the end.
Ended up using onkeyup, that appears to be far enough down the line that it will wipe out what is in the textbox.
I was really looking for the ajax filtered textbox functionality, but couldn't use that because we aren't using actual ajax controls in the application.
What is the difference between the LostFocus and the Leave events of TextBox?
Check the notes section on these links:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.lostfocus.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.leave.aspx
According to MSDN, there is difference when changing focus of a control. The Leave event occurs before a validation and LostFocus occurs after validation.
UPDATE: 14 Feb 2019
I see that I'm still getting views and upvotes on the answer that I posted couple of years ago. It has now become imperative that I include a (rather important) quote from the MSDN links above to avoid confusion among new programmers (note the difference of order esp. in case of focus by using the mouse or by calling the Focus method):
When you change the focus by using the keyboard (TAB, SHIFT+TAB, and
so on), by calling the Select or SelectNextControl methods, or by
setting the ContainerControl.ActiveControl property to the current
form, focus events occur in the following order:
Enter
GotFocus
Leave <--- before validation
Validating --
|<--- validation
Validated --
LostFocus <--- after validation
When you change the focus by using the mouse or by calling the Focus
method, focus events occur in the following order:
Enter
GotFocus
LostFocus <--- before validation
Leave <--- before validation
Validating --
|<--- validation
Validated --
N.B: Emphasis on text and indicators in the quote added by me
They happen at different points in the control's lifecycle. Depending on the method used, validation happens after Leave and before LostFocus.
See MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.lostfocus.aspx
Leave() event means that first executes keyboard event and then executes mouse event where as Lost() event means that first executes mouse event and then executes keyboard event.
To sum up, it either won't work for the keyboard or it won't work for the mouse. Considering you can't predict what input method will be used it's not very helpful.
However, that's not my point. LostFocus will happen when the form loads, Leave does not.
This would turn the text box yellow when the form is loaded.
Private Sub txtBox_LostFocus(sender As Object, e As EventArgs) Handles TextBox.LostFocus
txtBox.BackColor = Color.Yellow
End Sub
This would not.
Private Sub txtBox_TextLeave(sender As Object, e As EventArgs) Handles TextBox.Leave
txtBox.BackColor = Color.Yellow
End Sub
I am using background worker to do a long process on some files. I take the address of a directory from textBox1 and the address of a file that is used for the processing function from textBox2. I also have a ComboBox. Based on the selected value of the ComboBox the program chooses a different function through a simple switch case.
Now the problem is that I can not access the values of these textBoxes and the ComboBox in the BackGroundWorker_DoWork. I of course get the exception of accessing a control from a thread it wasn't created on. I have searched a lot about delegates and all that. The examples I have seen so far are all about assigning a text to the textBox inside the program. While what I want to do is to read the text that the user has inserted into the textBox. Since I'm not quite familiar with the concept of delegates, I want to know how I can read and use the Texts of textBoxes and the ComboBox and process them in the BackGroundWorker?
Sorry I cannot post the code here due to security policies.
/MoNoo
You don't say if this is WinForms, WPF or Silverlight, but in WPF you would do this using the Dispatcher property of the combobox, something like this:
string theText;
myComboBox.Dispatcher.Invoke( DispatcherPriority.Normal,
new Action( delegate()
{
theText = myComboBox.Text;
}
));
That will marshal the call onto the main thread and back again.
When a user presses the ESC key, I need to display a prompt.
How can I do this in Lotus Notes client?
Can you elaborate? Is this for one application, one form or the whole Lotus client? Why would you want to disable the esc key?
In the Queryclose event you can get a handle to the close event. Continue = false will prevent the form from closing:
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
msgbox "the message"
End Sub
** The original question changed (by a moderator) from it's original intent, which asked to detect AND ignore ESC key press in Lotus Notes. **
You need to use the "QueryClose" event (as others have mentioned), but how do you identify a "legitimate" way to close the form ? We need some logic to distinguish between someone actually clicking a button to "legitimately" close the form, and if someone hits the escape key or the "X" button in the window bar.
So, you need to use 2 form events, and an action button to do this.
In the QueryOpen event of the form
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
Dim session As New NotesSession
Call session.SetEnvironmentVar("CloseDoc",0,True)
End Sub
Your QueryClose event needs to look like this
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
Dim session As New NotesSession
Dim iCloseDoc As Integer
iCloseDoc = session.GetEnvironmentValue("CloseDoc", True)
If iCloseDoc <> 1 Then
continue = False
End If
End Sub
And you need to have an action button called "Close", on the form with this in it.
#SetEnvironment("CloseDoc";"1");
#PostedCommand([FileCloseWindow])
The LotusScript alternative looks like this
Sub Click(Source As Button)
Dim ws As New notesUIWorkspace
Dim session As New NotesSession
Call session.SetEnvironmentVar("CloseDoc",1,True)
Call ws.CurrentDocument.Close
End Sub
Now what's going on ? When you open the form, I set an environment variable for "CloseDoc", (QueryOpen event). If the user hits the "ESC" key or even clicks the "X" on the form to close the window the QueryClose event triggers.
When a request to close the form is detected, the QueryClose event then runs. I retrieve the "CloseDoc" environment variable which, in this case is still 0 (zero). If it's not equal to 1 then the close form will be aborted. You can add a messagebox there if you like.
Now the only way for the user to successfully close the form is for them to press the "Close" button. Which first sets the CloseDoc environment variable to 1, then call NotesUIDoc.close(). Although I am not a big fan of environment variables, it is handy in the case as you are able to record user activity without modifying the current document or another document. (That would be even messier, because you would have to clean up temporary documents, or you are forced to make changes to the document which won't work if the user only has reader access to the database or the current document).
This is relatively clean as the control is managed via a discrete envrionment variable that adds no overhead to the database performance and will not get in the way of any other functionality of applications. Some suggestions in the comments advises the use of global variables instead of environment variables and this quite is appropriate if you're using LotusScript exclusively, but if you have a mixture of formula and lotusScript, environment variables are common to both. But it's upto the developer to determine which.
This is one way I have over the years forced the user to click a specific button to close the document, and ignore "ESC" keys or the "X" button int he form window bar without any annoying messages and is free of performance issues.