pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/angular/angular/pull/67842/files

assets.com/assets/primer-primitives-7f694b60439d06c0.css" /> fix(forms): allow late-bound input types for signals forms by alxhub · Pull Request #67842 · angular/angular · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/forms/signals/src/directive/form_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ export class FormField<T> {

// Compute some helper booleans about the type of element we're sitting on.
private readonly elementIsNativeFormElement = isNativeFormElement(this.element);
private readonly elementAcceptsNumericValues = isNumericFormElement(this.element);
private readonly elementAcceptsTextualValues = isTextualFormElement(this.element);
private _elementAcceptsNumericValues: boolean | undefined;

/**
* Utility that casts `this.element` to `NativeFormControl` to avoid repeated type guards. Only
Expand Down Expand Up @@ -360,7 +360,8 @@ export class FormField<T> {
switch (key) {
case 'min':
case 'max':
return this.elementAcceptsNumericValues;
return (this._elementAcceptsNumericValues ??= isNumericFormElement(this.element));

case 'minLength':
case 'maxLength':
return this.elementAcceptsTextualValues;
Expand Down
37 changes: 37 additions & 0 deletions packages/forms/signals/test/web/form_field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,25 @@ describe('field directive', () => {
expect(element.min).toBe('5');
});

it('should apply min/max if type is late-bound to a numeric type during initialization', () => {
@Component({
imports: [FormField],
template: `<input [type]="inputType()" [formField]="f" />`,
})
class TestCmp {
readonly inputType = signal('number');
readonly min = signal(10);
readonly f = form(signal(15), (p) => {
min(p, this.min);
});
}

const fixture = act(() => TestBed.createComponent(TestCmp));
const input = fixture.nativeElement.firstChild as HTMLInputElement;

expect(input.min).toBe('10');
});

it('should bind to a custom control host directive', () => {
@Directive()
class CustomControlDir implements FormValueControl<number> {
Expand Down Expand Up @@ -3021,6 +3040,24 @@ describe('field directive', () => {
expect(element.getAttribute('maxlength')).toBeNull();
});

it('should apply maxLength if type is late-bound to a textual type during initialization', () => {
@Component({
imports: [FormField],
template: `<input [type]="inputType()" [formField]="f" />`,
})
class TestCmp {
readonly inputType = signal('email');
readonly f = form(signal('abc'), (p) => {
maxLength(p, 10);
});
}

const fixture = act(() => TestBed.createComponent(TestCmp));
const input = fixture.nativeElement.firstChild as HTMLInputElement;

expect(input.maxLength).toBe(10);
});

it('should be reset when field changes on native control', () => {
@Component({
imports: [FormField],
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy