Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date parsing doesn't seem to work #51

Open
gurugeek opened this issue Dec 10, 2019 · 0 comments
Open

date parsing doesn't seem to work #51

gurugeek opened this issue Dec 10, 2019 · 0 comments

Comments

@gurugeek
Copy link

I have a form

  router.get("/addpage") { _, response, _ in
        let title = ["title": "Adminpage", "date":Date()] as [String : Any]
        try response.render("addpage.stencil", context: title)
    }

and the relevant form


<form class="mui-form" method="POST">
        <legend>{{title}}</legend>
           <a href="/007/admin"> Back to Admin home </a>
           
     <div class="mui-textfield">
         <input type="text" id="title" name="title" placeholder="Enter page title/slug"
         <br>
         
         <div class="mui-textfield">
                <input type="text" id="date" name="date" value={{date}}"
                <br>


         <textarea class="editable" id="body" name="body"></textarea>
         <br>
         <button type="submit"  class="mui-btn mui-btn--raised">Save</button>
     </div>
      <input type="hidden" id="id" name="id" value="0" >
 </form>

my post route 
 router.post("/addpage") { request, response, _ in
        let page = try request.read(as: Page.self)
...

my struct is

struct Page: Codable, QueryParameter {
    var id: Int
    var title: String
    var body: String
    var date: Date
}

the error I receive is


[2019-12-10T10:38:49.491+01:00] [VERBOSE] [QueryDecoder.swift:128 decode(_:)] fieldName: id, fieldValue: Optional("0")
[2019-12-10T10:38:49.491+01:00] [VERBOSE] [QueryDecoder.swift:128 decode(_:)] fieldName: title, fieldValue: Optional("eee")
[2019-12-10T10:38:49.491+01:00] [VERBOSE] [QueryDecoder.swift:128 decode(_:)] fieldName: body, fieldValue: Optional("ee")
[2019-12-10T10:38:49.491+01:00] [VERBOSE] [QueryDecoder.swift:128 decode(_:)] fieldName: date, fieldValue: Optional("2019-12-10")
[2019-12-10T10:38:49.492+01:00] [ERROR] [QueryDecoder.swift:332 decodingError()] Could not process field named 'date'.
[2019-12-10T10:38:49.493+01:00] [ERROR] [RouterMiddlewareWalker.swift:72 next()] dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "date", intValue: nil)], debugDescription: "Could not process field named \'date\'.", underlyingError

I assume is because the format of date is wrong (but I see no other way to get the date to the add form template ? but also if date is null it still throws an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant