ponzu-cms / ponzu

Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
https://docs.ponzu-cms.org
BSD 3-Clause "New" or "Revised" License
5.67k stars 387 forks source link

Adding date/time field - followup to issue #315 #317

Closed Tom2Terrific closed 4 years ago

Tom2Terrific commented 4 years ago

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.

olliephillips commented 4 years ago

@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.

Tom2Terrific commented 4 years ago

Ollie:

That works for storing & retrieving, which is all that I anticipate! It was far simpler that it appeared. There are even arrows that allow a mouse to bump the day, month or year!

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

Tom

On 2019-09-20 04:30, Ollie Phillips wrote:

@Tom2Terrifc, 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.

-- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub [1], or mute the thread [2].

Links:

[1] https://github.com/ponzu-cms/ponzu/issues/317?email_source=notifications&email_token=AL46L6BX34JHKGOXOMUX2VLQKSC3DA5CNFSM4IYSEGL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7F7UJI#issuecomment-533461541 [2] https://github.com/notifications/unsubscribe-auth/AL46L6HL5MIJGPQCALNJCI3QKSC3DANCNFSM4IYSEGLQ

olliephillips commented 4 years ago

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.