-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels