Closed notmessenger closed 8 years ago
Given this data
theErrors: {
bio: 'I should not be empty'
}
and template
{{#ef-form
data=theProperties
errors=theErrors
as |f|
}}
{{/ef-form}}
this error state could be accessed via
{{#ef-form
data=theProperties
errors=theErrors
as |f|
}}
{{#if f.errorStates.bio}}
Is in an error state
{{/if}}
{{/ef-form}}
I am not aware of how to yield a dynamic hash property in https://github.com/ember-forge/ember-forge-ui/blob/form-components/app/templates/components/ef-form.hbs such that f.bio.isValid
could be used, let alone f.bio
. errorStates
is an object that has all of this data though and can be exposed in such a way as it is a "known" thing on the ef-form
component and is not dynamic.
We could create a helper that could give a cleaner syntax, though would likely need to be something along the lines of
{{#ef-form
data=theProperties
errors=theErrors
as |f|
}}
{{#if isValid "bio"}}
Is in an error state
{{/if}}
{{/ef-form}}
likely needing to also be namespaced, etc.
I'd suggest that in the form component you define a computed property that constructs whatever yielded API you need, then simply yield that property. This let's you leverage the full range of Javascript to build the API rather than just (hash ...)
@davewasmer There is a currently such a property being yielded like that, called errorStates
. Are you suggesting to dynamically create additional computed properties, one for each error property value, that can then be yielded? Even if that isn't exactly what you are suggesting I'm not sure how to follow your suggestion to be able to have the f.bio.isValid
with a computed property (regarding .isValid
).
I guess it would have to be something like f.fields.bio.isValid
, where fields
would be a single computed property that would compute it all. Just a suggestion though - that might be prohibitive from a perf perspective
https://github.com/ember-forge/ember-forge-ui/commit/1c32bf3b5bcf517ad0eccc026dfebd2a48e5fafb exposes f.errorStates
so that the example in https://github.com/ember-forge/ember-forge-ui/issues/157#issuecomment-245434383 is valid.
This, coupled with the error-state mixin, is enough for this issue to be closed for now. It can always be revisited if a different API is desired, but for now the functionality is provided.
The implementation will need to be fleshed out but the idea is that it will be possible to query the error state of properties in order to make decisions based off of them. For example, possibly,