[CLOSED] Combo - How to?

  1. #1

    [CLOSED] Combo - How to?

    I have an "auto lookup" combo box patterned off of this:
    https://examples2.ext.net/#/Form/Com...Custom_Search/

    This works fine for me except I have an issue. I need to ensure that the user either selects something exactly from the list or the field is blank. Because I have set ForceSelection =true, once I type something in and select it, I cannot simply delete it (the value comes back). How would you suggest that I effectively implement this scenario? Do I literally have to have a trigger button or manually have to handle the "Del"/"Backspace" keys or is there a setting on the control of which I am unaware?
    Last edited by Daniil; Jun 28, 2012 at 9:03 PM. Reason: [CLOSED]
  2. #2
    Hi,

    I am afraid I don't understand the following well.

    Quote Originally Posted by adelaney View Post
    I need to ensure that the user either selects something exactly from the list or the field is blank.
    Maybe, the following Change listener suites your needs.
    <Change Handler="console.log(Ext.isEmpty(newValue) ? 'empty' : 'not empty');" />
  3. #3
    Sorry, that didn't work - it threw an error.

    What I require is that the user may either select a valid option from the list or the combo is completely blank. Right now, when a user types in a value, the drop-down list appears and the combo forces a selection. That works fine. However, if after a selection, the user decides that the value should be blank, and tries to delete it, the combo puts back in the previous value. So again, BLANK or an EXACT list match are the only valid possible inputs. My question is how do I properly clear a selected value? Do I manually have to trap for the DEL/Backspace keys? Do I add the trigger button? Or, is there some configuration combination which I don't know about that allows for must select and blank to be valid?
  4. #4
    Quote Originally Posted by adelaney View Post
    Sorry, that didn't work - it threw an error.
    I guess because you tested with a browser without console.

    Quote Originally Posted by adelaney View Post
    What I require is that the user may either select a valid option from the list or the combo is completely blank. Right now, when a user types in a value, the drop-down list appears and the combo forces a selection. That works fine. However, if after a selection, the user decides that the value should be blank, and tries to delete it, the combo puts back in the previous value. So again, BLANK or an EXACT list match are the only valid possible inputs. My question is how do I properly clear a selected value? Do I manually have to trap for the DEL/Backspace keys? Do I add the trigger button? Or, is there some configuration combination which I don't know about that allows for must select and blank to be valid?
    According the details the best approach I can see is implementing an additional trigger to clear the ComboBox.
    https://examples2.ext.net/#/Form/Com...riggerButtons/

    And set up
    Editable="false"
  5. #5
    Yes, that example works. I assumed that a trigger button would work. However, I know my users will really push to use the Delete key as well. Can I capture that and use it the same way as the trigger button? I know in jQuery, I can attach events something like this:

    $(window).keyup(function(e) {
      if(e.keyCode == 46 && $("input:focus, textarea:focus").length == 0) {
        e.preventDefault();
        alert("delete key pressed!");
      }
    });
    Is there an equivalent to this for the combo control?
  6. #6
    Please look at the example.

    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.ComboBox1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "1", "item1" },
                    new object[] { "2", "item2" },
                    new object[] { "3", "item3" }
                };
                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 v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:ComboBox ID="ComboBox1" runat="server" EnableKeyEvents="true">        
            <Store>
                <ext:Store runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="value" />
                                <ext:ModelField Name="text" />
                            </Fields>
                        </ext:Model>
                    </Model>
                    <Reader>
                        <ext:ArrayReader />
                    </Reader>
                </ext:Store>
            </Store>
            <Listeners>
                <KeyDown Handler="if (e.getKey() === e.DELETE || e.getKey() === e.BACKSPACE) {
                                    e.preventDefault();
                                    App.Label1.appendLine('Delete or Backspace has been pressed');
                                }" />
            </Listeners>
        </ext:ComboBox>
    
        <ext:Label ID="Label1" runat="server" />
    </body>
    </html>
  7. #7
    That was just what I needed. Thanks.

Similar Threads

  1. [CLOSED] combo sort
    By Vasudhaika in forum 1.x Legacy Premium Help
    Replies: 16
    Last Post: Jan 12, 2012, 7:29 PM
  2. Replies: 6
    Last Post: Aug 25, 2011, 2:13 PM
  3. Replies: 3
    Last Post: May 11, 2010, 10:36 AM
  4. Replies: 4
    Last Post: Sep 18, 2009, 9:49 AM
  5. [CLOSED] Combo Box
    By marcellus in forum 1.x Help
    Replies: 5
    Last Post: Sep 18, 2008, 10:08 PM

Tags for this Thread

Posting Permissions