Adds FieldIdentifier parameter to FluentInputBase #2114
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request
📖 Description
This PR adds a new parameter
Field
(of typeFieldIdentifier
) toFluentInputBase
. I'm working on a system that allows users to create their own dynamic forms, this means my model contains a list of fields and each of those has a base class where the value is stored as anobject?
and inheriting classes override this with a specific type. When passing to input components theValue
parameter gets cast to the correct type, but theFluentValidationMessage
component can only be passed theobject?
version due toFieldIdentifiers
not supporting theUnaryExpression
that is created by casting. This means that theFluentInputBase
has a different internalFieldIdentifier
due to the unboxing, and means the validation message shows correctly when the value is invalid but the field stays showing as valid. By allowing theFieldIdentifier
to be manually set this limitation can be overcome.In normal statically typed models this additional parameter is not needed as everything will already work. However for dynamic use cases like mine, where design-time accessors are not possible, a
FieldIdentifier
works best.ValueExpression
will also not work in this case as it also requires statically typed accessors.#1489 added a similar feature for
FluentValidationMessage
so I largely used the same code.Example
This is a basic example of how this works, it uses the FluentValidation library to simplify validating the dynamic model. This example is simpler than my use case but demonstrates the same issue:
Without using
Field
and invalid the fields are still marked as validWhen using
Field
and invalid the fields are now correctly marked as invalid🎫 Issues
No issues currently reported, but for this niche use case it is required
👩💻 Reviewer Notes
📑 Test Plan
No tests affected by this extra parameter, but all existing tests for
FluentInputBase
components pass. I have tested this code by creating custom versions of the number and text inputs in my project and verifying it works in both the above example and a more complex scenario, as well as making sure existing forms that don't use this new parameter still work.✅ Checklist
General
Component-specific
⏭ Next Steps