Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    trouble getting date formatting to work when the field is read-only

    I’m having trouble getting date formatting to work when the field is read-only.


    I've configured it in the ds.xml file...

    Code:
    <field name="some_date" title="Some Date" type="date"
    canEdit="false" readOnlyDisplay="static" dateFormatter="TOJAPANSHORTDATE"/>

    I've tried setting the format in Java on the date, and on the form...

    Code:
    form.getField("some_date").setDateFormatter(DateDisplayFormat.TOJAPANSHORTDATE);
    Code:
    form.setDateFormatter(DateDisplayFormat.TOJAPANSHORTDATE);
    It gets rendered like this...

    Some Date: Apr 1 2018

    I want it to get formatted like this...

    Some Date: 2018/04/01

    I've tried all sorts of variations using datetime, text, StaticTextItem etc. but they all have issues. The above is the closest to what I think it should be.

    Any ideas?

    Thanks!
    -Chris

    SmartClient Version: v11.0p_2016-08-09/Enterprise Deployment (built 2016-08-09)
    FireFox 24.x ... yeah, I know it's ancient but that's the target.

    #2
    None of those are correct. Set the formatter on the FormItem, and do so while you are constructing the FormItem, before setFields().

    However, a simpler and more complete solution is just to use the Japanese locale, which will also change the input format to match.

    If you don't want to actually use the Japanese locale, see also dataSourceField.format for a simply way to do formatting that isn't the default for a locale. This is also valid to set in XML.

    Comment


      #3
      Thanks for the quick response! ... Oh well. I was hoping to not have to write all the FormItems in Java.

      Comment


        #4
        You don't have to, we just provided multiple ways to avoid this.

        DateUtil also allows you write a custom formatter in Java, which affects all date rendering, with a single call.

        Comment


          #5
          I'm confused. ... So I can do it in the ds.xml file? That'd be great!
          Can you post a simple example?

          I tried DateUtil.setShortDateDisplayFormatter() too. But still no luck.

          Comment


            #6
            Again, see docs for DataSourceField.format. We already noted this above.

            Comment


              #7
              I have looked at DataSourceField.format at https://www.smartclient.com/smartgwt...ld.html#format
              but it's not really an example.
              I see it uses FormatString https://www.smartclient.com/smartgwt...matString.html
              which the docs have notes on formats.
              But I don't see how to use it in the ds.xml file.

              I assume using dateFormatter="TOJAPANSHORTDATE" would use StringFormat internally.

              Can you just post a simple sample like a modification of what's shown below that would use StringFormat (or whatever)?
              Code:
              <field name="some_date" title="Some Date" type="date"
                     canEdit="false" readOnlyDisplay="static" dateFormatter="TOJAPANSHORTDATE"/>
              Last edited by christoferjennings; 12 Dec 2017, 10:04.

              Comment


                #8
                I finally got this to do what I wanted.

                Code:
                <field name="some_date" title="Some Date" type="date" useTextField="true" textAlign="left"
                       canEdit="false" readOnlyDisplay="static" dateFormatter="toJapanShortDate"/>
                Tested with smartgwtee version 6.1-20180103 (from POM)

                Comment

                Working...
                X