Calling Plugin Extension methods on click of the button in the widget

Calling Plugin Extension methods on click of the button in the widget

This question is not answered

HI,

I have a simple widget with two text boxes and a submit button.

------------------------------------------------------------------------------------

Enter name: [TextBox1]

Enter email: [TextBox2]

[Submit Button]                

------------------------------------------------------------------------------------

The requirement is, on click of the button, we have to pass the values of both the textboxes to the extension method $MyExtension.MyMethod.

This method takes two params, inserts the value into the database and returns a boolean to indicate success or failure.

Widget code:

-------------------

<input type="text" id="NameText" />

<br />

<input type="text" id="EmailText" />

<br />

<input type="button" id="SaveButton" value="Save User"  onclick=$MyExtension.MyMethod('john', 'john@example.com');  />

Issue:

--------

When I view the source of the page after it gets rendered, I see the following:

<input type="button" id="SaveButton" value="Save User"  onclick=True />

So, as soon as the page is loaded, the extension method is invoked and substituted with the value (its return value).

Please let me know, if there is any way to invoke this method only onclick of the  button.

Thanks in advance.

Verified Answer
  • You are thinking of Velocity like its javascript and its not.  It will be executed on the server before your widget renders. 
     
    You should be wiring up the button click using javascript and doing a client side post to a .vm file you create in the widget.  In that widget you can call your method.
     
    If its sensitive info you can use a normal submit button that submits the form, check for post using $core_v2_page.IsPost() and then read the value for your field from the forms collection ($core_v2_page.GetFormValue(‘uniqueIdOfInput’)). You should only use this method though if the data is sensitive like you are passing a password.  Otherwise use the first method.
     
    You can see an example of #1 if you look at the “Create API Key” widget.  You can see where a jQuery object is created and inside there a click is is validation that ultimately fires a method that posts to create.vm in the widget.  In create.vm is where you execute your extension.
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Madhu Sadlapur [mailto:bounce-Madhu_Sadlapur@communities.telligent.com]
    Sent: Wednesday, January 23, 2013 4:31 AM
    To: discussion_evolution@communities.telligent.com
    Subject: [Telligent Evolution Platform Discussion] Calling Plugin Extension methods on click of the button in the widget
     

    HI,

    I have a simple widget with two text boxes and a submit button.

    ------------------------------------------------------------------------------------

    Enter name: [TextBox1]

    Enter email: [TextBox2]

    [Submit Button]                

    ------------------------------------------------------------------------------------

    The requirement is, on click of the button, we have to pass the values of both the textboxes to the extension method $MyExtension.MyMethod.

    This method takes two params, inserts the value into the database and returns a boolean to indicate success or failure.

    Widget code:

    -------------------

    <input type="text" id="NameText" />

    <br />

    <input type="text" id="EmailText" />

    <br />

    <input type="button" id="SaveButton" value="Save User"  onclick=$MyExtension.MyMethod('john', 'john@example.com');  />

    Issue:

    --------

    When I view the source of the page after it gets rendered, I see the following:

    <input type="button" id="SaveButton" value="Save User"  onclick=True />

    So, as soon as the page is loaded, the extension method is invoked and substituted with the value (its return value).

    Please let me know, if there is any way to invoke this method only onclick of the  button.

    Thanks in advance.

All Replies
  • You are thinking of Velocity like its javascript and its not.  It will be executed on the server before your widget renders. 
     
    You should be wiring up the button click using javascript and doing a client side post to a .vm file you create in the widget.  In that widget you can call your method.
     
    If its sensitive info you can use a normal submit button that submits the form, check for post using $core_v2_page.IsPost() and then read the value for your field from the forms collection ($core_v2_page.GetFormValue(‘uniqueIdOfInput’)). You should only use this method though if the data is sensitive like you are passing a password.  Otherwise use the first method.
     
    You can see an example of #1 if you look at the “Create API Key” widget.  You can see where a jQuery object is created and inside there a click is is validation that ultimately fires a method that posts to create.vm in the widget.  In create.vm is where you execute your extension.
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Madhu Sadlapur [mailto:bounce-Madhu_Sadlapur@communities.telligent.com]
    Sent: Wednesday, January 23, 2013 4:31 AM
    To: discussion_evolution@communities.telligent.com
    Subject: [Telligent Evolution Platform Discussion] Calling Plugin Extension methods on click of the button in the widget
     

    HI,

    I have a simple widget with two text boxes and a submit button.

    ------------------------------------------------------------------------------------

    Enter name: [TextBox1]

    Enter email: [TextBox2]

    [Submit Button]                

    ------------------------------------------------------------------------------------

    The requirement is, on click of the button, we have to pass the values of both the textboxes to the extension method $MyExtension.MyMethod.

    This method takes two params, inserts the value into the database and returns a boolean to indicate success or failure.

    Widget code:

    -------------------

    <input type="text" id="NameText" />

    <br />

    <input type="text" id="EmailText" />

    <br />

    <input type="button" id="SaveButton" value="Save User"  onclick=$MyExtension.MyMethod('john', 'john@example.com');  />

    Issue:

    --------

    When I view the source of the page after it gets rendered, I see the following:

    <input type="button" id="SaveButton" value="Save User"  onclick=True />

    So, as soon as the page is loaded, the extension method is invoked and substituted with the value (its return value).

    Please let me know, if there is any way to invoke this method only onclick of the  button.

    Thanks in advance.

  • Thank you very much Patrick for your ideas. :)