Change data on the way in
Closed this issue · 4 comments
How do we modify the data on the way in? For example, my model has a Date
field. Obviously I don't want that showing up in the text box as-is. I need to run it through some type of DateFormatter
before it's filled in as the value of the field, for example when I'm doing an edit request.
Good question! Ideally we would have control over the en/decoder that's being used so we could use a custom dateDecodingStrategy
and dateEncodingStrategy
but I don't see how we'd do that.
I haven't gotten around to testing it but my idea for dealing with this was to have date as a String
on your Submission
struct and Create
and do the conversion there, using a computed var for instance.
This situation also calls for another tag ("dategroup") to set the correct input type. I'll try to get an example up in my test project as soon as I have time again.
I forked this thinking I could help with some templates, but it's not the full "project", like with a .xcodeproj file, so I wasn't sure how to participate.
@grosch You contributions would be very welcome! The xcodeproj is generally not part of any server-side swift package or project. It needs to be generated from the Package.swift
file using swift package generate-xcodeproj
or Vapor's vapor xcode
command, see https://docs.vapor.codes/3.0/getting-started/hello-world/.
Have you already joined the community on Discord? If so, what is your username there? If not, you might like to check out: https://discordapp.com/invite/vapor 😃