[CLOSED] How to format the value of a DisplayField in javascript?

  1. #1

    [CLOSED] How to format the value of a DisplayField in javascript?

    Hi,

    I have a details FormPanel having a few DisplayFields databound to a GridPanel. Is there any way to format the value of the DisplayField after it's loaded into the form, e.g. format the date or currency, etc.
    I have attempted to use a Render listener on a DisplayField. However, every time it fires, the value of the DisplayField is empty but is populated after the renderer completes.

    Thanks,

    Vadym

    <script>
            var formatDate = function (displayField) {
                alert(displayField.getValue());   // Empty
            };
    </script>
                                      
    <ext:DisplayField ID="DisplayDate1" runat="server" DataIndex="Date1">
    <Listeners>
    <Render Fn="formatDate" />
    </Listeners>
    </ext:DisplayField>
    Last edited by Daniil; Mar 01, 2012 at 3:02 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please try AfterRender instead of Render.
  3. #3
    Hi Daniil,

    I tried that, too with the same result - getValue() returns empty string. What is the call to be made to set the DisplayFiled text in the renderer function?

    Thanks,

    Vadym
  4. #4
    Then I would suggest you to override the setValue method - it will work for an initial text and a text applied on the fly.

    Example
    <%@ 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 runat="server">
        <title>Ext.NET Example</title>
    
        <script type="text/javascript">
            var mySetValue = function (v) {
                this.setRawValue(v + " FORMATTED");
                return this;
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:DisplayField ID="DisplayField1" runat="server" Text="Hello World!">
                <CustomConfig>
                    <ext:ConfigItem Name="setValue" Value="mySetValue" Mode="Raw" />
                </CustomConfig>
            </ext:DisplayField>
            <ext:Button runat="server" Text="Change text">
                <Listeners>
                    <Click Handler="DisplayField1.setValue('I am the new text!');" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
  5. #5
    Thank you Daniil!

    This works. Somehow, for my form databinding scenario, I didn't have to provide any listener for the FormPanel. I assume that mySetValue() specified in CustomConfig overrides the default setValue() function for the DisplayField so it's invoked every time setValue() would be called.

    <ext:DisplayField ID="DisplayDate1" runat="server" Width="320" DataIndex="Date1">
         <CustomConfig>
              <ext:ConfigItem Name="setValue" Value="mySetValue" Mode="Raw" />
         </CustomConfig>
    </ext:DisplayField>
    Thanks,

    Vadym
  6. #6
    Quote Originally Posted by vadym.f View Post
    Somehow, for my form databinding scenario, I didn't have to provide any listener for the FormPanel. I assume that mySetValue() specified in CustomConfig overrides the default setValue() function for the DisplayField so it's invoked every time setValue() would be called.
    Yes, that's right.
  7. #7
    Thanks, that has answered my question.

    Vadym

Similar Threads

  1. [CLOSED] ComboBox DisplayField with HTML?
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 24, 2012, 8:31 PM
  2. Get value of DisplayField of Combobox
    By littletran in forum 1.x Help
    Replies: 0
    Last Post: May 17, 2012, 7:32 AM
  3. [CLOSED] [1.0] DisplayField Value initialization
    By smmille1 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 15, 2010, 11:31 PM
  4. Replies: 3
    Last Post: Mar 30, 2010, 3:03 AM
  5. DisplayField of the ComboBox
    By Maia in forum 1.x Help
    Replies: 2
    Last Post: Jun 04, 2009, 10:46 AM

Posting Permissions