[CLOSED] Resetting a Form on the client

  1. #1

    [CLOSED] Resetting a Form on the client

    Hi,

    Please consider the code sample below. I'm curious what other call is required to select the initial value of a ComboBox on the server so that it doesn't get reset to empty on the client. I'm selecting an option on the server thinking that it's persisted into the form values. However, the Reset button cancels it out.

    <%@ 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)
            {
                var list = new List<object>
                {
                    new {CountryName = "Canada", CountryID = 1},
                    new {CountryName = "Great Britain", CountryID = 2},
                    new {CountryName = "United States", CountryID = 3}
                };
    
                this.Store1.DataSource = list;
                this.Store1.DataBind();
    
                ComboBox1.SelectedItems.Clear();
                ComboBox1.SelectedItems.Add(new Ext.Net.ListItem(2));
    
                TextField1.Text = "Anything goes here";
            }
        }
    </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 id="Head1" runat="server">
        <title>Ext.Net 2.x</title>
        <ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" Mode="Script" />
        <ext:ResourcePlaceHolder ID="ResourcePlaceHolder2" runat="server" Mode="Style" />
    </head>
    <body>
        <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server">
        </ext:ResourceManager>
        <ext:Viewport runat="server" Layout="FitLayout">
            <Items>
                <ext:FormPanel runat="server" ID="FormPanel1">
                    <Items>
                        <ext:ComboBox ID="ComboBox1" runat="server" DisplayField="CountryName" ValueField="CountryID"
                            TypeAhead="true" Editable="true" MinChars="2" SelectOnFocus="true" EmptyText="Select Country..."
                            FieldLabel="Select Country" QueryMode="Local">
                            <Store>
                                <ext:Store ID="Store1" runat="server">
                                    <Model>
                                        <ext:Model ID="Model1" runat="server" IDProperty="CountryID">
                                            <Fields>
                                                <ext:ModelField Name="CountryName" />
                                                <ext:ModelField Name="CountryID" />
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                </ext:Store>
                            </Store>
                        </ext:ComboBox>
                        <ext:TextField runat="server" ID="TextField1" FieldLabel="Description">
                        </ext:TextField>
                        <ext:CheckboxGroup ID="CheckboxGroup1" runat="server" Width="300" FieldLabel="Some Options">
                            <Items>
                                <ext:Checkbox runat="server" BoxLabel="Option 1" InputValue="1" Checked="true">
                                </ext:Checkbox>
                                <ext:Checkbox runat="server" BoxLabel="Option 2" InputValue="2">
                                </ext:Checkbox>
                            </Items>
                        </ext:CheckboxGroup>
                    </Items>
                    <TopBar>
                        <ext:Toolbar runat="server">
                            <Items>
                                <ext:Button runat="server" Text="Reset Form" Icon="Cancel">
                                    <Listeners>
                                        <Click Handler="App.FormPanel1.reset();">
                                        </Click>
                                    </Listeners>
                                </ext:Button>
                            </Items>
                        </ext:Toolbar>
                    </TopBar>
                </ext:FormPanel>
            </Items>
        </ext:Viewport>
        </form>
    </body>
    </html>
    Last edited by Daniil; Aug 08, 2013 at 2:25 PM. Reason: [CLOSED]
  2. #2
    Hello!

    We are investigating this issue.

    Temporarily please use the following overriding:

    Ext.form.field.ComboBox.override({
    	setInitValue: function (value) {
    		this.initialSelectedItems = value;
    		if (this.store.getCount() > 0) {
    			this.setSelectedItems(value);
    		} else {
    			this.store.on("load", Ext.Function.bind(this.setSelectedItems, this, [value]), this, { single : true });
    		}
    	},
    	
    	reset: function () {
    		if (!Ext.isEmpty(this.initialSelectedItems)) {
    			var me = this;
    			me.beforeReset();
    			me.setSelectedItems(me.initialSelectedItems);
    			me.clearInvalid();
    			// delete here so we reset back to the original state
    			delete me.wasValid;
    		} else
    			this.callParent();
    		
    		me.applyEmptyText();
    	}
    });
  3. #3
    Thanks Daulet, it works!
  4. #4
    Fixed in SVN, please update. Thank you for the report.
  5. #5
    Confirmed.

Similar Threads

  1. Problem resetting a form
    By vadym.f in forum 1.x Help
    Replies: 15
    Last Post: Nov 26, 2014, 1:47 PM
  2. [CLOSED] Problem resetting a form
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: May 21, 2013, 3:36 AM
  3. problem after resetting form controls populated
    By Ewerton93 in forum 1.x Help
    Replies: 1
    Last Post: Apr 25, 2012, 3:48 PM
  4. Form Panel Client Validation Problem
    By vivekrane1986 in forum 1.x Help
    Replies: 0
    Last Post: Jun 18, 2010, 9:26 AM
  5. [0.8.1] Commit form fields (client)
    By wazige in forum 1.x Legacy Premium Help
    Replies: 0
    Last Post: Nov 25, 2009, 8:59 AM

Tags for this Thread

Posting Permissions