Hi Tory,
On 02/19/2016 08:56 PM, Tory Berra wrote:
> When a form is posted to my handler, and it fails validation I spit back
> the view with a local variable called errors.body. It will have various
> properties on it with names that correspond with the form input names.
>
> A tricky situation is on checkboxes that dont have values. Nunjucks will
> take "" as falsy, which makes sense.
>
> |
> value="{{ value }}"{{"checked"iferrors.body[name]}}/>
> |
I don't fully understand the use case here. Is it with `value` or with
`errors.body[name]` that you're concerned about an empty string
evaluating to false? Seems like the latter, but why would "checkboxes
don't have values" imply that the error would be an empty string? In any
case, I can answer the general question:
> Is there a way to use Object.prototype.hasOwnProperty() in my expression?
Not directly, but fairly easily -- you just need to define a filter
function that uses `hasOwnProperty` and add it to your environment using
`addFilter`, then you could do something like `if
obj|hasOwnProperty(name)` in your template (if you named your filter
`hasOwnProperty`).
Carl