[CLOSED] Question on Using simple plugin to perform basic setDisable task

  1. #1

    [CLOSED] Question on Using simple plugin to perform basic setDisable task

    Ext.form.btnToggleTarget = function(config) {
        Ext.apply(this, config);
    }
    
    
    Ext.form.btnToggleTarget = Ext.extend(Ext.Button, 
    {
        target: null,
        init: function(config) {
            Ext.apply(this, config);
            this.target = Ext.getCmp(this.targetid).selModel;
            this.target.on('selectionchange', this.autoToggle, this);
            this.setDisabled(true);
        },
        autoToggle: function() {
            //         this.setDisabled(!Ext.isEmpty(this.target.getSelected()));
            this.setDisabled(false);
        }
    });
    
    
    Ext.preg('btnToggleTarget', Ext.form.btnToggleTarget);
    <ext:Button ID="RXDeleteButton" IDMode="Explicit" runat="server" Text="Delete this medication"  Icon="Delete">
         <CustomConfig>
            <ext:ConfigItem Name="targetid" Value="MedGrid" Mode="Value" />
           </CustomConfig>
           <Plugins>
            <ext:GenericPlugin runat="server" InstanceName="Ext.form.btnToggleTarget" ID="btnToggleTgt">
              </ext:GenericPlugin>
            </Plugins>
    </ext:Button>
    I need to venture into the world of plugins so I figured I'd start off simple and work my way up. I don't fully grasp the sequence of events in using a plugin. All I'm trying to do is add functionality to a specific button (hence the use of plugin) so I can set it up to listen for a change on a grid and disable or enable based on a valid selection. While this code doesn't give me any errors, it also does not enable or disable the button which the plugin is attached to. I'm sure I'm doing something wrong and I'm just not seeing the obvious. Any pointers?

    FYI: I commented out the operational code that does the setDisable in lieu of forcing a disable to see if that worked and it didn't. But if I call setDisable in the browser console, it works fine. So I think what is going on is that the apply stuff is not applying in the proper hierarchical direction.. ? if so, then I am fundamentally misunderstanding how to write plugins, in which case, I need some directions on how to do this properly.

    Thanks
    Last edited by Daniil; Feb 18, 2014 at 6:15 AM. Reason: [CLOSED]
  2. #2
    Hi @jlosi,

    Being a premium member, please ask in the Premium forums. Then there is a better chance we don't miss your question.

    You are almost there. Please see the changes.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "test1", "test2", "test3" },
                    new object[] { "test4", "test5", "test6" },
                    new object[] { "test7", "test8", "test9" },
                };
                store.DataBind();
            }
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    
        <ext:ResourcePlaceHolder runat="server" Mode="ScriptFiles" />
    
        <script type="text/javascript">
            Ext.form.btnToggleTarget = function (config) {
                Ext.apply(this, config);
            }
    
            Ext.form.btnToggleTarget = Ext.extend(Ext.Button, {
                target: null,
    
                init: function (btn) {
                    this.btn = btn;
                    this.target = Ext.getCmp(this.targetid).selModel;
                    this.target.on('selectionchange', this.autoToggle, this);
                    
                    btn.setDisabled(true);
                },
    
                autoToggle: function () {
                    this.btn.setDisabled(false);
                }
            });
    
            Ext.preg('btnToggleTarget', Ext.form.btnToggleTarget);
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
                <Store>
                    <ext:Store runat="server">
                        <Reader>
                            <ext:ArrayReader>
                                <Fields>
                                    <ext:RecordField Name="test1" />
                                    <ext:RecordField Name="test2" />
                                    <ext:RecordField Name="test3" />
                                </Fields>
                            </ext:ArrayReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column Header="Test1" DataIndex="test1" />
                        <ext:Column Header="Test2" DataIndex="test2" />
                        <ext:Column Header="Test3" DataIndex="test3" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
    
            <ext:Button runat="server" Text="The Button with Plugin">
                <Plugins>
                    <ext:GenericPlugin runat="server" InstanceName="Ext.form.btnToggleTarget">
                        <CustomConfig>
                            <ext:ConfigItem Name="targetid" Value="GridPanel1" Mode="Value" />
                        </CustomConfig>
                    </ext:GenericPlugin>
                </Plugins>
            </ext:Button>
        </form>
    </body>
    </html>
  3. #3
    Ahhhh.. I was even closer before I posted. I actually had the config on the plugin.. really all I needed was a reference to the btn in the plugin. I knew it was something ridiculously silly that I was missing.

    Thanks!

    p.s. I didn't realize I wasn't in premium. I had like 10 tabs open to the forums reading various threads on the topic :)

    [CLOSED]

Similar Threads

  1. Replies: 1
    Last Post: Oct 11, 2013, 3:02 PM
  2. Just Simple Question About TreePanel
    By teamsar in forum 2.x Help
    Replies: 3
    Last Post: Jan 26, 2013, 3:23 AM
  3. [CLOSED] DateFiled simple question
    By Pyropace in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 15, 2012, 10:37 PM
  4. Very simple question TreePanel check or uncheck all
    By apocalipse9 in forum 1.x Help
    Replies: 0
    Last Post: Jun 17, 2010, 12:36 AM
  5. [CLOSED] Simple radiogroup question
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 24, 2009, 5:56 AM

Tags for this Thread

Posting Permissions