Calling Plugin Extension methods on Selection change of dropdown and getting back response value in the widget

Calling Plugin Extension methods on Selection change of dropdown and getting back response value in the widget

This question is not answered

Hi,

I have Widget with dropdown ,on selection change of the dropdown i need to call a Plugin Method that has input paramaters.How to achieve this.

Dropdown code

=============

<select  id="drop" name="drop">

              <option value="">Select</option>

              #foreach( $item in $SchoolResponse)                    

               <option value="$item.SchoolId">$item.Schoolname</option>                

              #end

        </select>

Selection change event

=====================

$("#drop").change(function () {

var strvalue = "";

        var strrid = "";

        $("#drop option:selected").each(function () {

            strvalue += $(this).text() + " ";

            strrid += $(this).val();

         });

});

In the above method i want to call the plugin method on selection change of the dropdown and set back the response value to a varible..Kindly provide your inputs.

All Replies
  • A plugin is just a class, therefore you need to make whatever method you are trying to call public and then retrieve the instance of your plugin via Telligent.Evolution.Extensibility.Version1.PluginManager.Get<T>().FirstOrDefault().
     
    You need to also account for the plugin manager returning null when its not enabled. or multiple instances(thus the FirstOrDefault()).
     
    You must then expose the plugin through a custom REST endpoint or custom scripted content fragment extension. http://telligent.com/community/developers/w/developer7/31466.creating-new-widget-extensions.aspx
     
    If you use a custom endpoint just call it via javascript.  Or for a custom extension you can do an asynchronous post from javascript to a vm file in your widget.  The easiest way to see this is by example.  Edit the Create/Edit API key widget and you will see how this works(post to create.vm)
     
     
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Srini@Infy [mailto:bounce-SriniInfy@communities.telligent.com]
    Sent: Wednesday, February 06, 2013 7:39 AM
    To: discussion_evolution@communities.telligent.com
    Subject: [Telligent Evolution Platform Discussion] Calling Plugin Extension methods on Selection change of dropdown and getting back response value in the widget
     

    Hi,

    I have Widget with dropdown ,on selection change of the dropdown i need to call a Plugin Method that has input paramaters.How to achieve this.

    Dropdown code

    =============

    <select  id="drop" name="drop">

                  <option value="">Select</option>

                  #foreach( $item in $SchoolResponse)                    

                   <option value="$item.SchoolId">$item.Schoolname</option>                

                  #end

            </select>

    Selection change event

    =====================

    $("#drop").change(function () {

    var strvalue = "";

            var strrid = "";

            $("#drop option:selected").each(function () {

                strvalue += $(this).text() + " ";

                strrid += $(this).val();

             });

    });

    In the above method i want to call the plugin method on selection change of the dropdown and set back the response value to a varible..Kindly provide your inputs.

  • I am not able to get the plugin method values ,below is the steps i followed.

    I have created plugin method and on "Selection change" of dropdown registering the ".vm file" & passing selected value id.Below is the code

    content script code

    ===============

    #registerEndOfPageHtml('telligent.evolution.widgets.studentKeyList')

       <script type="text/javascript" src="$core_v2_encoding.HtmlAttributeEncode($core_v2_widget.GetFileUrl('grd.js'))"></script>

    #end

    #registerEndOfPageHtml()

       <script type="text/javascript">

       //<![CDATA[

    jQuery(document).ready(function(j){

         //On dropdown selection change  below function is called        

           $("#drop").change(function () {

                  var schoolvalue = "";

                  var schoolid = "";

                   $("#drop option:selected").each(function () {

                     schoolvalue += $(this).text() + " ";

                     schoolid += $(this).val();

                  });

                  alert(schoolid);              

                     jQuery.telligent.evolution.widgets.studentKeyList.register({

                     wrapper: "#$core_v2_encoding.JavascriptEncode($core_v2_widget.WrapperElementId)",

                     nameInputschoolid:schoolid,

                     createUrl: "$core_v2_encoding.JavascriptEncode($core_v2_widget.GetExecutedFileUrl('grids.vm'))"

                       });  

                 });              

            });

    //]]>

    </script>

    #end

    "grd.js" file code

    ==============

    (function($) {

       var studentKeyList = function(context) {    

           $.telligent.evolution.post({

    url: context.createUrl,

    data: {

    Name: $(context.nameInputschoolid).val()

    },

    success: function (response) {

    window.location.href = window.location.href;

    }

    });

    };

    var api = {

        register:function(context) {  

                 context.nameInputschoolid = $(context.nameInputschoolid);

                studentKeyList(context);

    }

    };

    if (typeof $.telligent === 'undefined') { $.telligent = {}; }

    if (typeof $.telligent.evolution === 'undefined') { $.telligent.evolution = {}; }

    if (typeof $.telligent.evolution.widgets === 'undefined') { $.telligent.evolution.widgets = {}; }

    $.telligent.evolution.widgets.studentKeyList = api;

    }(jQuery));

    "grids.vm"  file code

    ===============

    #if ($core_v2_page.IsPost)

      #set($school = $core_v2_page.GetFormValue('Name'))

      #set($student =  $HTMLPlugin.Getliststudent())    

      $student    

    #end

    As  you said above,I have gone through the "Create API Key"  widget of "ui.js" & "create.vm"  file there it is given for on click of submit button, i need it for on selection change/on change of dropdown. Kindly provide the steps.  

  • That widget is not meant to be cut and paste, just a working example.  You will have to infer the wire ups yourself. 
     
    This also does not call your vm on change unless I am lost in the formatting.  It looks like it will try and just call your vm file immediately.
     
    There are several other discrepancies that the example I mentioned gives that are missing here.
     
    First, there shouldn’t be any javascript outside the javascript object you created.  You should be wiring up the change event in register by passing in the Id ( based on a unique id using $core_v2_widget.UniqueId(‘’)).  Essentially in the same place the example widget wires up validation.  Unless you use the unique id you cannot have that widget exist more than once.
     
    Second, do not use Telligent.evolution.widgets… as a jquery namespace.  You should use your own.
     
    Third, the VM file you are posting to does not define the return content type(Json?Text?Html?).  You are then just sending back a $students variable but what does your method return? What is $students? Based on your success method it looks like you are just refreshing the page.  If you are doing a page refresh anyway there is no reason to do a vm file post.  Make your change event refresh the page and alter the querystring with your query data.  Then let your widget read the query string and build your grid.
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Srini@Infy [mailto:bounce-SriniInfy@communities.telligent.com]
    Sent: Thursday, February 07, 2013 7:37 AM
    To: discussion_evolution@communities.telligent.com
    Subject: RE: [Telligent Evolution Platform Discussion] Calling Plugin Extension methods on Selection change of dropdown and getting back response value in the widget
     

    I am not able to get the plugin method values ,below is the steps i followed.

    I have created plugin method and on "Selection change" of dropdown registering the ".vm file" & passing selected value id.Below is the code

    content script code

    ===============

    #registerEndOfPageHtml('telligent.evolution.widgets.studentKeyList')

       <script type="text/javascript" src="$core_v2_encoding.HtmlAttributeEncode($core_v2_widget.GetFileUrl('grd.js'))"></script>

    #end

    #registerEndOfPageHtml()

       <script type="text/javascript">

       //<![CDATA[

    jQuery(document).ready(function(j){

         //On dropdown selection change  below function is called        

           $("#drop").change(function () {

                  var schoolvalue = "";

                  var schoolid = "";

                   $("#drop option:selected").each(function () {

                     schoolvalue += $(this).text() + " ";

                     schoolid += $(this).val();

                  });

                  alert(schoolid);              

                     jQuery.telligent.evolution.widgets.studentKeyList.register({

                     wrapper: "#$core_v2_encoding.JavascriptEncode($core_v2_widget.WrapperElementId)",

                     nameInputschoolid:schoolid,

                     createUrl: "$core_v2_encoding.JavascriptEncode($core_v2_widget.GetExecutedFileUrl('grids.vm'))"

                       });  

                 });              

            });

    //]]>

    </script>

    #end

    "grd.js" file code

    ==============

    (function($) {

       var studentKeyList = function(context) {    

           $.telligent.evolution.post({

    url: context.createUrl,

    data: {

    Name: $(context.nameInputschoolid).val()

    },

    success: function (response) {

    window.location.href = window.location.href;

    }

    });

    };

    var api = {

        register:function(context) {  

                 context.nameInputschoolid = $(context.nameInputschoolid);

                studentKeyList(context);

    }

    };

    if (typeof $.telligent === 'undefined') { $.telligent = {}; }

    if (typeof $.telligent.evolution === 'undefined') { $.telligent.evolution = {}; }

    if (typeof $.telligent.evolution.widgets === 'undefined') { $.telligent.evolution.widgets = {}; }

    $.telligent.evolution.widgets.studentKeyList = api;

    }(jQuery));

    "grids.vm"  file code

    ===============

    #if ($core_v2_page.IsPost)

      #set($school = $core_v2_page.GetFormValue('Name'))

      #set($student =  $HTMLPlugin.Getliststudent())    

      $student    

    #end

    As  you said above,I have gone through the "Create API Key"  widget of "ui.js" & "create.vm"  file there it is given for on click of submit button, i need it for on selection change/on change of dropdown. Kindly provide the steps.