Announcement

Collapse
No announcement yet.

Retyped.openui5 events

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

    Retyped.openui5 events

    Hi guys,

    I'm having some problems using jquery events with retyped.

    I'm trying to use the onsapenter method https://openui5.hana.ondemand.com/#/....Input.oninput

    In javascript this works:

     
     myInput.onsapenter = function(e) {    window.alert("hi!"); }
    however, I don't know to create the onsapenter method in Bridge and how to call it to get the same output as the javascript code. Note that the method should have a jquery event parameter.

    Could you please help me?
    Thank you

    #2
    Hi emumanu,

    I see DefinitelyTyped typings (as well as Retyped.openui5 package) are built for version 1.40, but your reference is pointing to 1.54.7. It seems OpenUI5 1.40 just doesn't contain the method/event you mentioned.

    If you still want to use the older bindings for a fresh OpenUI5 library, you will need to extend the class manually:
    using Bridge;
    using System;
    
    using static Retyped.openui5;
    using static Retyped.dom;
    
    namespace Demo
    {
        public class Program
        {
            public static void Main()
            {
                var input = new sap.m.Input("");
                input.set_onsapenter(() =>
                {
                    window.alert("hi!");
                });
            }
        }
    
        [External]
        public static class OpenUI5Extensions
        {
            [Template("{input}.onsapenter = {handler}")]
            public static extern void set_onsapenter(this sap.m.Input input, Action handler);
        }
    }
    Last edited by Andrey; 2018-07-12 @ 02:18 PM.

    Comment


      #3
      Andrey, Don't worry about the current openui5 version on DefinitelyTyped. I'm creating it manually.

      However, in your code I do not see any reference to jquery Event. I put a simple example but what about if the code was something like this:

      function(eventObject) {
          if (elem.attr("value").match(/evil/)) { 
              eventObject.preventDefault();    
              elem.addClass("evil");  
          }
      }
      So using Action won't do.

      BR,
      Manu

      Comment


        #4
        Andrey, let me rephrase my question as I realize it can be confusing.

        Is there a specific delegate to work with jquery Events in retyped.jquery or I have to stick to Action<jquery.jQuery.Event>?

        Comment


          #5
          As for event types, I guess you'll need one of the following instead of jquery.jQuery.Event:
          JQueryMouseEventObject
          JQueryKeyEventObject
          JQueryInputEventObject
          JQueryEventObject
          BaseJQueryEventObject
          I'm not aware of a specific official delegate declared in Retyped.jquery. There are some delegates generated by Retyped though, but their names are originated from the methods where they were mentioned the first time - you can use them, but cautiously, they could be renamed or even removed in the future package versions.

          public delegate object bindFn(jquery.JQueryEventObject eventObject);
          
          public delegate object blurFn(jquery.JQueryEventObject eventObject);
          
          public delegate object changeFn(jquery.JQueryEventObject eventObject);
          
          public delegate object clickFn(jquery.JQueryEventObject eventObject);
          
          public delegate object contextmenuFn(jquery.JQueryMouseEventObject eventObject);
          
          public delegate object dblclickFn(jquery.JQueryEventObject eventObject);
          
          public delegate object delegateFn(jquery.JQueryEventObject eventObject);
          
          public delegate object focusFn(jquery.JQueryEventObject eventObject);
          
          public delegate object focusinFn(jquery.JQueryEventObject eventObject);
          
          public delegate object focusoutFn(jquery.JQueryEventObject eventObject);
          
          public delegate object hoverFn(jquery.JQueryEventObject eventObject);
          
          public delegate object keydownFn(jquery.JQueryKeyEventObject eventObject);
          
          public delegate object keypressFn(jquery.JQueryKeyEventObject eventObject);
          
          public delegate object keyupFn(jquery.JQueryKeyEventObject eventObject);
          
          public delegate object loadFn2(jquery.JQueryEventObject eventObject);
          
          public delegate object mousedownFn(jquery.JQueryMouseEventObject eventObject);
          
          public delegate object mouseenterFn(jquery.JQueryMouseEventObject eventObject);
          
          public delegate object mouseleaveFn(jquery.JQueryMouseEventObject eventObject);
          
          public delegate object mousemoveFn(jquery.JQueryMouseEventObject eventObject);
          
          public delegate object mouseoutFn(jquery.JQueryMouseEventObject eventObject);
          
          public delegate object mouseoverFn(jquery.JQueryMouseEventObject eventObject);
          
          public delegate object mouseupFn(jquery.JQueryMouseEventObject eventObject);
          
          public delegate object offFn(jquery.JQueryEventObject eventObject);
          
          public delegate object offFn2(jquery.JQueryEventObject eventObject, params object[] args);

          Comment


            #6
            Thank you Andrey.

            The only problem I see now is that even this works:

            [Template("{input}.onsapenter = {handler}")] 
             public static extern void set_onsapenter(this sap.m.Input input, Action handler);
            There are a lot of onsap* methods in sap.m.Input. Is there any way to use the delegate name in a template? Trying something like this:
            [Template("{oldHandler} = {newHandler}")]   
             public static extern void set_onsap(Action oldHandler, Action newHandler);
            creates a Bridge.fn.cacheBind in the left hand side instead of the function name. I don't want to create a template for every onsap* method, and I don't want to pass a string for the method name. Do you know how to overcome that problem? Thank you, Manu

            Comment

            Working...
            X