Announcement

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

    Custom Date Widget Behavior?

    Hey there, I'm using a DateItem widget on my form. Works pretty well, but normally when I'm handling dates (on other non-AJAX forms on the site), I allow users to select "unknown" for day and month, which encode as "00". I need to be able to do the same thing with the date entry on my SmartClient form. Any suggestions? Is there something I can override somewhere to accomplish this?

    On a related note, when displaying dates with "unknown" fields, I like to only display as much of the date as is known. So, a date value of "1985-00-00" should display as "1985".
    Last edited by shmax; 20 Sep 2008, 21:40.

    #2
    You may not want to use a DateItem for this, since a DateItem expects to create an instance of Date, which can't represent 1985-00-00. You could combine your own triple-select style date item via using three SelectItems, and you could add a FormItemIcon that still shows an isc.DateChooser for picking a specified date.

    Comment


      #3
      Thanks for the suggestion, I've set up three SelectItems like you suggested, and it seems to work just fine.

      Here's the next tricky part. Under the hood, dates with "unknown" components are assumed to be 1. So, if a user specifies "unknown" for month and day, but 1985 for the year, then I treat that as "1985-01-01", and that's what ultimately gets stored in my database (along with separate day, month, and year columns, so I know which ones are "unknown").

      Because I know that the user selected "unknown" for the day and month, I like to display such a date simply as "1985" (even though in date operations, I treat it as "1985-01-01".

      I have a "date" field in one of my ListGrids, which is associated with this date we've been talking about. It doesn't know about the "unknown" components of the date, because it's looking at the adjusted date. I could just use a simple text field instead, and show the date formatted the way I want, but then sorting wouldn't work properly.

      So, to boil all this down to a question, is it possible for a date field in a ListGrid to sort on one value, but show another?

      Comment


        #4
        Yes, look at http://www.smartclient.com/docs/6.5.....displayFormat, and note that you can provide your own formatting function rather than using one of the SmartClient-provided ones. That may not cut it for you, since you're going to need more than just the date itself to decide how to format, right? In that case, have a look at http://www.smartclient.com/docs/6.5....ormatCellValue - this will let you provide any custom formatting you like to any field.

        Comment


          #5
          Thanks much, I'll definitely have uses for formatCellValue. But I was able to fix my issue with a different approach; I discovered the "displayField" parameter for ListGrid fields, and used that to refer to another field which I prepare on the server side. Seems to work like a charm, so far.

          Speaking of formatCellValue, the next little issue I'll be tackling is the concept of foreign currencies. I have a "retail price" field, and I'm using the currency formatter, but all it seems to display is dollars ($). I need to show yen, yuan, euros, anything, really. I can understand that one can't expect SmartClient to know about every currency in the world, so is this something I should handle on my own using formatCellValue?

          Originally posted by Isomorphic
          Yes, look at http://www.smartclient.com/docs/6.5.....displayFormat, and note that you can provide your own formatting function rather than using one of the SmartClient-provided ones. That may not cut it for you, since you're going to need more than just the date itself to decide how to format, right? In that case, have a look at http://www.smartclient.com/docs/6.5....ormatCellValue - this will let you provide any custom formatting you like to any field.

          Comment


            #6
            Interesting use of displayField. Another approach, just fyi, is to use a sortNormalizer (see the Reference).

            For currencies, formatCellValue works, but if currency fields appear in multiple contexts, you should take a look at the SimpleType APIs. A SimpleType is essentially a reusable field type.

            Comment

            Working...
            X