Angular form does not allow standard html attributes for boolean and number inputs
jyjor opened this issue · comments
Describe the bug
Boolean and number attributes in Angular do not follow typical HTML conventions. Here are some examples:
<div myInput>
- In Angular, myInput
is ''
, but in standard HTML it is the boolean value true
.
<div myInput="true">
- In Angular, myInput
is the string 'true'
, but in standard HTML it is the boolean value true
.
Angular has transform functions to address these discrepancies and it looks like the number and boolean inputs are missing these. This is a simple problem with a simple fix, and I would love put up a PR to fix it.
Side note - I spoke with Corbin at ng-conf during a lunch break, was very impressed with him from our short conversation, and he inspired me to take a look. He also said he won't respond with "
Your minimal, reproducible example
https://stackblitz.com/edit/stackblitz-starters-pszun1?file=src%2Fmain.ts
Steps to reproduce
- Open the linked example
- Note the error on line 19 of main.ts
NG2: Type '""' is not assignable to type 'boolean | undefined'.
- Change the line to
asyncAlways="true"
to get the same error - Change the line to
[asyncAlways]="true"
and it will be fixed. - In addition to
asyncAlways
, this also applies toasyncDebounceMs
andpreserveValue
attributes.
Expected behavior
asyncAlways
and asyncAlways="true"
should be equivalent to [asyncAlways]="true"
and asyncAlways="false"
should be equivalent to [asyncAlways]="false"
.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: Linux
- Browser: Chrome
- Version 0.17.0
TanStack Form adapter
None
TanStack Form version
0.17.0
TypeScript version
5.4.2
Additional context
In the "TanStack Form adapter" drop down above, there is no option for "angular-form", but that is the version with the error.
If you're up for it, I'd accept a PR adding the transforms 😊 Let's just make sure it doesn't break the TS type inferencing