Web Dialog Question

  1. 4 months ago

    Jon O

    Jun 6 Pre-Release Testers, Xojo Pro Chicago Area USA
    Edited 4 months ago

    I need to have a custom web dialog pop up that allows the user to enter some text and then return that text to a method that then does some processing of that text.

    In desktop apps, I have a modal window that I have created. In that window, I have a function called "RunDialog" that has the following code:

    Public Function RunDialog(LabelText As String, Optional FieldText as String) as String
      DialogLabel.Text = LabelText
      
      If FieldText <> "" Then
        UserInput.Text = FieldText
      End If
      
      me.ShowModal
      return theReturnValue
    End Function

    To show my "User Dialog" I call the following code (TitleString is just a dummy variable in this example - this string is basically telling the user what information you want them to enter)

    Dim w as New UserDialog
    Dim s as string = w.RunDialog(TitleString)

    Now in Web apps, I don't want to create a new page so I've created a WebDialog. I have set its type to modal. The RunDialog function is exactly the same as the desktop. Here is how I open this one:

    Dim wc As New WebSessionContext(CurrentWebSession)
    Dim w As New WebUserDialog
    sval = w.RunDialog(TitleString)

    I need to add the WebSessionContext as this call is actually coming from a server based object so I need to track the session.

    This works but there's a problem. When the WebDialog is constructed, it shows that its type is 3 = Modal. However, when the open event fires (and also the shown event), the type is 1 = Sheet. So the WebDialog is not maintaining it's type between the time it is constructed and the time that it is shown. That seems to be a bug to me, but maybe I am doing something wrong but I don't see what. Everything works just as I want it, except the dialog is a sheet which is what I don't want.

    I've added break points in the constructor method and can see that type is 3 before Super.Constructor executes and type is 3 after Super.Constructor executes. But I also put a break point between the code above after the WebDialog is created and before RunDialog is called. The type has already changed back 1. That just doesn't seem right.

    UPDATE: OK, an update... If I delete the constructor method (I don't actually need to use it), then things work fine. I'm not sure why having the constructor method in place mucks up the WebDialog but it does. I will probably file a bug report on this...

  2. Jon O

    Jun 6 Pre-Release Testers, Xojo Pro Chicago Area USA

    Well, my idea doesn't work anyhow because the modal WebDialog is not really modal. The code continues to run and so nothing happens. I'll have to figure out some way to make it modal....

  3. Greg O

    Jun 6 Xojo Inc

    @Jon O Well, my idea doesn't work anyhow because the modal WebDialog is not really modal. The code continues to run and so nothing happens. I'll have to figure out some way to make it modal....

    WebDialogs have a Dismissed event that you can use to get the value.

  4. Olivier C

    Jun 6 Pre-Release Testers, Xojo Pro Europe (Belgium, France)

    Jon, indeed WebDialogs are asynchronous.
    You have to deal with it ;-)

    When needed I’m using the event Dismissed to know when the dialog is closed (or hidden) before proceeding with next steps.

  5. Jon O

    Jun 6 Pre-Release Testers, Xojo Pro Chicago Area USA

    @Greg OLone WebDialogs have a Dismissed event that you can use to get the value.

    Yeah, but the problem is then the rest of my code has already run. I really needed it modal. So I changed the code to this:

    Public Function RunDialog(LabelText As String, Optional FieldText as String) as String
      DialogLabel.Text = LabelText
      
      If FieldText <> "" Then
        UserInput.Text = FieldText
      End If
      
      Me.Show
      
      Do
        app.SleepCurrentThread(10)
      Loop Until theReturnValue <> ""
      
      return theReturnValue  
    End Function

    That seems to run fine and everything stays responsive. And yes, I don't allow a null return value. If the user cancels entering anything I set theReturnValue to something else so I know it's was a cancelled decision by the user.

  6. Greg O

    Jun 6 Xojo Inc

    @Jon O I'm not sure why having the constructor method in place mucks up the WebDialog but it does. I will probably file a bug report on this...

    Please don’t. There’s already at least two and we’ve already fixed this in Web 2.0.

  7. Jon O

    Jun 6 Pre-Release Testers, Xojo Pro Chicago Area USA

    @Greg OLone Please don’t. There’s already at least two and we’ve already fixed this in Web 2.0.

    OK. Thanks for letting me know. I won't then! :)

  8. Olivier C

    Jun 6 Pre-Release Testers, Xojo Pro Europe (Belgium, France)

    @Greg OLone Please don’t. There’s already at least two and we’ve already fixed this in Web 2.0.

    Good to know ! Would be even better to have an idea when Web2.0 can be expected ... ;-)
    I’m holding multiple projects because they could become standard features.

    But I know Xojo doesn’t give timelines ;-(

  9. Jay M

    Jun 6 Pre-Release Testers, Xojo Pro Austin TX

    @Greg OLone This suggests you are not longer fixing Web 1.0 bugs?

  10. 3 months ago

    Greg O

    Jun 6 Xojo Inc

    @Jay M @Greg OLone This suggests you are not longer fixing Web 1.0 bugs?

    No. What it means is that we're no longer working on things that would require refactoring large swaths of the current web framework. Getting Constructors to work properly would require a huge amount of work and we'd risk breaking people's projects.

  11. Tobias B

    Jun 11 Pre-Release Testers, Xojo Pro Bern, Switzerland

    @Jon O That seems to run fine and everything stays responsive.

    to my understanding, this cannot work. The Me.Show will generate some JavaScript to be sent to the browser, but this will be queued up till the current Event Thread ends. With the Sleep-Loop you effectively hinder it to end, so I'd assume you wait forever or the theReturnValue is being set by another thread - not unlikely as you mention that is not happening in a regular roundtrip. If that actually works, please let me know what kind of Server Event / Thread this code runs in as the pattern could allow a variety of creative hacks :)

or Sign Up to reply!