[CLOSED] [#476] BasicForm call to setValues() fails to persist DropDownField's value

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] [#476] BasicForm call to setValues() fails to persist DropDownField's value

    Hi,

    This thread is related to http://forums.ext.net/showthread.php...undefined-quot.

    To observe the issue, comment out the BasicForm override, click on the "Save Form" button and then on "Reset Fields".

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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>FormPanel - Ext.NET Examples</title>
        <ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" Mode="Script" />
        <ext:ResourcePlaceHolder ID="ResourcePlaceHolder2" runat="server" Mode="Style" />
        <script>
            var saveForm = function () {
                DropDownField1.setValue("Changed Value");
                var fieldValues = FormPanel1.getForm().getFieldValues();
                FormPanel1.getForm().setValues(fieldValues);
            };
    
            Ext.form.BasicForm.override({
                setValues: function (values) {
                    if (Ext.isArray(values)) {
                        for (var i = 0, len = values.length; i < len; i++) {
                            var v = values[i];
                            var f = this.findField(v.id);
                            if (f) {
                                f.setValue(v.value);
                                if (this.trackResetOnLoad) {
                                    f.originalValue = f.getValue();
                                }
                            }
                        }
                    } else {
                        var field, id;
                        for (id in values) {
                            if (!Ext.isFunction(values[id]) && (field = this.findField(id))) {
                                field.setValue(values[id]);
                                if (this.trackResetOnLoad) {
                                    field.originalValue = field.getValue();
                                    // DropDownField fix
                                    if (field instanceof Ext.net.DropDownField)
                                        field.originalText = field.getValue();
                                }
                            }
                        }
                    }
                    return this;
                },
            });
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:FormPanel ID="FormPanel1" runat="server" Title="Form Panel" Padding="5" ButtonAlign="Left"
                TrackResetOnLoad="true">
                <Items>
                    <ext:DropDownField ID="DropDownField1" runat="server" Editable="false" FieldLabel="DropDown Field" TriggerIcon="Search" Text="Default Value">
                        <Component>
                            <ext:Panel runat="server"></ext:Panel>
                        </Component>
                    </ext:DropDownField>
                </Items>
                <Buttons>
                    <ext:Button runat="server" Text="Save Form">
                        <Listeners>
                            <Click Handler="saveForm();" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button runat="server" Text="Reset Fields">
                        <Listeners>
                            <Click Handler="FormPanel1.getForm().reset();" />
                        </Listeners>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
        </form>
    </body>
    </html>
    Last edited by Daniil; Apr 22, 2014 at 7:40 PM. Reason: [CLOSED]
  2. #2
    Hi Vadym,

    Thank you for the report. Created an Issue:
    https://github.com/extnet/Ext.NET/issues/476
  3. #3
    Fixed in v1, revision #5809. A slightly different fix.

    As for v2, it appears to be not reproducible there.
  4. #4
    Thanks, it seems OK. However, I still need to reset both properties of the DropDownField to an empty string if I want to clear it:

                    DropDownField1.originalValue = "";
                    DropDownField1.originalText = "";
  5. #5
    Well, yes, it persists because of TrackResetOnLoad="true" setting.

    You are going to do the same thing with another fields, aren't?
  6. #6
    Pretty much, except that most of them don't require resetting more than one value property. I'm fine as long as it's a normal course of events.
  7. #7
    I get it. In your case you can operate with .originalText only.
    delete DropDownField1.originalText;
    A DropDownField's originalValue is used if it is configured with Mode="ValueText".
  8. #8
    Quote Originally Posted by Daniil View Post
    I get it. In your case you can operate with .originalText only.
    delete DropDownField1.originalText;
    A DropDownField's originalValue is used if it is configured with Mode="ValueText".
    I've tested it but an error gets thrown:

    Unhandled exception at line 18, column 557275 in /extjs/ext-all-js/ext.axd?v=27503
    I've had similar problems with DropDownFields trying to set its value to null, which I believe what the call to delete does.
  9. #9
    Could you, please, post the exact sample you are testing with?
  10. #10
    It's not quite the same as my full fledged test case but it should give you some context. Click on the second button twice or once and then try to expand the DropDownField.

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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>FormPanel - Ext.NET Examples</title>
        <ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" Mode="Script" />
        <ext:ResourcePlaceHolder ID="ResourcePlaceHolder2" runat="server" Mode="Style" />
        <script>
            var saveForm = function () {
                DisplayField1.setValue("Changed Value");
                DropDownField1.setValue("Changed Value");
                var fieldValues = FormPanel1.getForm().getFieldValues();
                FormPanel1.getForm().setValues(fieldValues);
            };
    
            var resetDropDownField = function () {
                delete DropDownField1.originalText;
                //DropDownField1.originalText = "";
                DropDownField1.reset();
            };
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:FormPanel ID="FormPanel1" runat="server" Title="Form Panel" Padding="5" ButtonAlign="Left"
                TrackResetOnLoad="true">
                <Items>
                    <ext:DisplayField ID="DisplayField1" runat="server" Text="Default Value"></ext:DisplayField>
                    <ext:DropDownField ID="DropDownField1" runat="server" Editable="false" FieldLabel="DropDown Field" TriggerIcon="Search" Text="Default Value">
                        <Component>
                            <ext:Panel runat="server"></ext:Panel>
                        </Component>
                    </ext:DropDownField>
                </Items>
                <Buttons>
                    <ext:Button runat="server" Text="Save Form">
                        <Listeners>
                            <Click Handler="saveForm();" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button runat="server" Text="Reset DropDownField">
                        <Listeners>
                            <Click Handler="resetDropDownField();" />
                        </Listeners>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
        </form>
    </body>
    </html>
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] CompositeField and BasicForm.getFieldValues
    By anup in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 31, 2013, 4:01 PM
  2. Replies: 0
    Last Post: Jan 22, 2013, 2:50 PM
  3. [CLOSED] Dynamic Formpanel Setvalues
    By tpayn in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 02, 2012, 9:21 AM
  4. [CLOSED] Problem with formpanel.setvalues
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 08, 2010, 1:19 PM
  5. Replies: 0
    Last Post: Apr 23, 2009, 6:46 AM

Tags for this Thread

Posting Permissions