Announcement

Collapse
No announcement yet.

JQUERY UI Dialog Issue

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    JQUERY UI Dialog Issue

    Bridge.NET rocks.
    Having said that. I encountered an issue with the retyped jquery ui and seemingly some other libraries too.
    A jQuery dialog with

    var div = jquery.Self("div");
    div.jqueryui().dialog(new JQueryUI.DialogOptions()
    {
        buttons = new JQueryUI.DialogButtonOptions[]
        {
            new JQueryUI.DialogButtonOptions()
            {
                text = "OK",
                click = (evv)=>
                {
                    return true;
                }
            }
        },
        width = 480,
        height = 320,
        autoOpen = true
    });
    generates the javascript

    div.dialog({ buttons: System.Array.init([($t = new (Bridge.virtualc("JQueryUI.DialogButtonOptions"))( ), $t.text = "OK", $t.click = function (evv) {
    var formData = formBuilder.XCMS_Web_Client_Plugins$XCMS$Interface $Web$Client$IXWebClientFormBuilder$getFormData(div Form[0]);
    return Bridge.box(true, System.Boolean, System.Boolean.toString);
    }, $t)], Bridge.virtualc("JQueryUI.DialogButtonOptions")), width: Bridge.box(480, System.Int32), height: 320, autoOpen: true });
    and throws an exception as
    "Uncaught DOMException: Failed to execute 'setAttribute' on 'Element': '$init' is not a valid attribute name."
    I understand why the exception happen because of all the metadata added to the options when created.

    Is there a way to make the JQueryUI.DialogButtonOptions an objectliteral
    Last edited by geoffrey.mcgill; 2019-01-08 @ 06:52 PM.

    #2
    Hi Sake402,

    Welcome to Bridge! Thanks for posting this question and simplified code sample.

    I don't have an answer for you at the moment, but we are investigating the issue.

    Comment


      #3
      Thanks for your quick response.

      Just to say that simply creating a new empty class that inherit from JQueryUI.DialogButtonOptions and marking the new class with [ObjectLiteral] fixes the issue for now. Would like to know if there is a better alternative.

      [ObjectLiteral]
      class MDialogButtonOptions : JQueryUI.DialogButtonOptions { }  
      
      var div = jquery.Self("div");
      
      div.jqueryui().dialog(new JQueryUI.DialogOptions()
      {
          buttons = new JQueryUI.DialogButtonOptions[]
          {
              new MDialogButtonOptions()
              {
                  text = "OK",
                  click = (evv)=>
                  {
                      return true;
                  }
              }
          },
          width = 480,
          height = 320,
          autoOpen = true
      });
      Last edited by geoffrey.mcgill; 2019-01-08 @ 07:36 PM.

      Comment


        #4
        This appears to be a defect (limitation?) in Retyped which happens under a unique set of scenarios that are present in the jQueryUI .d.ts file. It's a scenario we think we can improve, but we don't have the resources available for us to work on this right now.

        We came up with the exact same workaround as your last code sample and that appears to be the best solution for now.

        https://deck.net/d0ed6fb54815198c06cf946bd41ed3a2

        public class Program
        {
            public static void Main()
            {
                // Existing
                var dbo1 = new DialogButtonOptions
                {
                    text = "Click Me"
                };
        
                // Work-around
                var dbo2 = new MyDialogButtonOptions
                {
                    text = "Click Me"
                };
            }
        }
        
        // DialogButtonOptions class generated by Retyped:
        [External]
        [IgnoreCast]
        [Virtual]
        public class DialogButtonOptions : Retyped.IObject
        {
            public virtual string text { get; set; }
        
            // ...
        }
        
        // Custom wrapper,
        // to get round the initialization issue.
        [ObjectLiteral]
        public class MyDialogButtonOptions : DialogButtonOptions
        {
        }
        Last edited by geoffrey.mcgill; 2019-01-08 @ 08:01 PM.

        Comment


          #5
          A GitHub issue has been created to track progress on the defect discussed above:
          https://github.com/Retyped/Retyped/issues/73

          Comment

          Working...
          X