ponzu-cms/ponzu

Adding date/time field - followup to issue #315

Tom2Terrific opened this issue · 3 comments

Pushing my limited Go skills to their limits, I've managed (with a few hints from Steve and Ollie) to get date input working! (I also found that boolean is supported). The form offered MM/DD/YYYY and allowed me to enter a date. Unforunately I get an error upon Save, and suppose that BeforeSave would be the cure, but I'm at a loss as to how and where to apply it.

Error decoding post form for edit handler: Commtest schema: error converting value for "date"

type Commtest struct {
item.Item

    Title      string  `json:"title"`
    Author     string  `json:"author"`
    Rating     float64 `json:"rating"`
    Body       string  `json:"body"`
    WebsiteUrl string  `json:"website_url"`
    Startdate  time.Duration  `json:"date"`

}
When I used "time.Time" the compiler complained: Type 'time.Time' for field 'Startdate' not supported.

editor.Field{
View: editor.Input("Startdate", c, map[string]string{
"label": "Startdate",
"type": "date",
"placeholder": "Enter the Startdate here",
}),
},

Any help would be appreciated, by me and any other ponzu user in need of date support.

@Tom2Terrific, revert Startdate from time.Duration to string. Turns out that just works. I've just tested it. Obviously if you wanted to start performing operations and comparisons on the date you'd likely need to code to make a time.Time type from the string in Ponzu, but you might do that in your client application. If it's a simple log type store, this might be all you need.

Now I can move on to the complex
parsing of CSV files which was the goal of the project --- calculate
commissions.

Cool. Good luck with your project. Closing this one.