[CLOSED] Combo selected text

Page 2 of 2 FirstFirst 12
  1. #11
    Quote Originally Posted by Adrian View Post
    Using your example it is still the case that if you type a custom entry which is not in the list of items both ComboBox1.SelectedItem.Text and ComboBox1.Text (or ComboBox1.Value) fail to retrieve the correct text/value - the text/value will default to the previous selected list item.
    Please clarify did you apply the fix and rebuild the Ext.NET sources?

    Quote Originally Posted by Adrian View Post
    Also, if a combo box is not assigned a pre-selected value (ie it is left blank) and the user does not select a listed item, but rather enters a custom value, you will get an 'Object reference not set to an instance of an object' error on a direct event.
    Confirmed. We are looking into it.

    Please check a SelectedItem on null.
    Last edited by Daniil; Jan 31, 2012 at 7:26 AM.
  2. #12
    Yes, I can confirm we've applied the fix to LoadPostData in ComboBoxBase.cs and rebuilt Ext.Net sources.

    A.
  3. #13
    Quote Originally Posted by Adrian View Post
    I can confirm we've applied the fix to LoadPostData in ComboBoxBase.cs and rebuilt Ext.Net sources.
    Confirmed. LoadPostData is not enough. The fix is related to more files.

    Please add the following thing into a page's <head>. This doesn't require rebuilding the Ext.NET sources.

    Fix
    <ext:ResourcePlaceHolder runat="server" Mode="ScriptFiles" />
    
    <script type="text/javascript">
        Ext.form.field.ComboBox.override({
            hiddenName : "",
    
            fieldSubTpl: [
                '<div class="{hiddenDataCls}" role="presentation"></div>',
                '<input id="{id}" type="{type}" ',
                    '<tpl if="size">size="{size}" </tpl>',
                    '<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>',
                    '<tpl if="name">name="{name}"</tpl>',
    
                    'class="{fieldCls} {typeCls}" autocomplete="off" />',
                '<div id="{cmpId}-triggerWrap" class="{triggerWrapCls}" role="presentation">',
                    '{triggerEl}',
                    '<div class="{clearCls}" role="presentation"></div>',
                '</div>',
                {
                    compiled: true,
                    disableFormats: true
                }
            ],
    
            setHiddenValue: function(values){
                var me = this,
                    name = me.hiddenName, 
                    i;
                
                if (!me.hiddenDataEl || !name) {
                    return;
                }
                values = Ext.Array.from(values);
                var dom = me.hiddenDataEl.dom,
                    childNodes = dom.childNodes,
                    input = childNodes[0],
                    valueCount = values.length,
                    childrenCount = childNodes.length;
            
                if (!input && valueCount > 0) {
                    me.hiddenDataEl.update(Ext.DomHelper.markup({
                        tag: 'input', 
                        type: 'hidden', 
                        name: name
                    }));
                    childrenCount = 1;
                    input = dom.firstChild;
                }
                while (childrenCount > valueCount) {
                    dom.removeChild(childNodes[0]);
                    -- childrenCount;
                }
                while (childrenCount < valueCount) {
                    dom.appendChild(input.cloneNode(true));
                    ++ childrenCount;
                }
                for (i = 0; i < valueCount; i++) {
                    childNodes[i].value = values[i];
                }
            }
        });
    </script>
    Here is the full example.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void GetValue(object sender, DirectEventArgs e)
        {
            string msg;
    
            if (this.ComboBox1.SelectedItem != null)
            {
                string v = this.ComboBox1.SelectedItem.Value;
                string t = this.ComboBox1.SelectedItem.Text;
                msg = string.Format("Text: {0}<br/>Value: {1}", t, v);
            }
            else
            {
                msg = "The ComboBox is empty.";
            }
            X.Msg.Alert("ComboBox", msg).Show();
        }
     
        protected void SetItem(object sender, DirectEventArgs e)
        {
            this.ComboBox1.Value = "2";
             
            //or
             
            //this.ComboBox1.Text = "2";
     
            //or
             
            //this.ComboBox1.SetValue("2");
        }
     
        protected void SetText(object sender, DirectEventArgs e)
        {
            this.ComboBox1.Value = "Hello World!";
     
            //or
     
            //this.ComboBox1.Text = "Hello World!";
     
            //or
     
            //this.ComboBox1.SetValue("Hello World!");
        }
    </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 v2 Example</title>
    
        <ext:ResourcePlaceHolder runat="server" Mode="ScriptFiles" />
    
        <script type="text/javascript">
            Ext.form.field.ComboBox.override({
                hiddenName : "",
    
                fieldSubTpl: [
                    '<div class="{hiddenDataCls}" role="presentation"></div>',
                    '<input id="{id}" type="{type}" ',
                        '<tpl if="size">size="{size}" </tpl>',
                        '<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>',
                        '<tpl if="name">name="{name}"</tpl>',
    
                        'class="{fieldCls} {typeCls}" autocomplete="off" />',
                    '<div id="{cmpId}-triggerWrap" class="{triggerWrapCls}" role="presentation">',
                        '{triggerEl}',
                        '<div class="{clearCls}" role="presentation"></div>',
                    '</div>',
                    {
                        compiled: true,
                        disableFormats: true
                    }
                ],
    
                setHiddenValue: function(values){
                    var me = this,
                        name = me.hiddenName, 
                        i;
                
                    if (!me.hiddenDataEl || !name) {
                        return;
                    }
                    values = Ext.Array.from(values);
                    var dom = me.hiddenDataEl.dom,
                        childNodes = dom.childNodes,
                        input = childNodes[0],
                        valueCount = values.length,
                        childrenCount = childNodes.length;
            
                    if (!input && valueCount > 0) {
                        me.hiddenDataEl.update(Ext.DomHelper.markup({
                            tag: 'input', 
                            type: 'hidden', 
                            name: name
                        }));
                        childrenCount = 1;
                        input = dom.firstChild;
                    }
                    while (childrenCount > valueCount) {
                        dom.removeChild(childNodes[0]);
                        -- childrenCount;
                    }
                    while (childrenCount < valueCount) {
                        dom.appendChild(input.cloneNode(true));
                        ++ childrenCount;
                    }
                    for (i = 0; i < valueCount; i++) {
                        childNodes[i].value = values[i];
                    }
                }
            });
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:ComboBox ID="ComboBox1" runat="server" LazyMode="Instance">
                <Items>
                    <ext:ListItem Text="Item 1" Value="1" />
                    <ext:ListItem Text="Item 2" Value="2" />
                </Items>
                <SelectedItems>
                    <ext:ListItem Index="0" />
                </SelectedItems>
            </ext:ComboBox>
            <ext:Button runat="server" Text="Get value" OnDirectClick="GetValue" />
            <ext:Button runat="server" Text="Set item" OnDirectClick="SetItem" />
            <ext:Button runat="server" Text="Set text" OnDirectClick="SetText" />
        </form>
    </body>
    </html>
  4. #14
    I can confirm the code above fixes the issue for DP1.
    Thanks guys. Appreciate the rapid response.

    Adrian.
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 6
    Last Post: Aug 25, 2011, 2:13 PM
  2. [CLOSED] Combo Clearing Selected Text in IE?
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 11, 2011, 11:51 AM
  3. Replies: 3
    Last Post: Aug 21, 2010, 5:26 AM
  4. [CLOSED] get more than one text from combo box
    By sharif in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 07, 2010, 10:13 AM
  5. Replies: 10
    Last Post: Apr 05, 2010, 1:42 AM

Tags for this Thread

Posting Permissions