Skip to content

signal forms disabled state not in sync with it's disabled source signal #66241

@urielzen

Description

@urielzen

Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

Yes

Description

Given the sample below the isDisabled signal is false, but the disabled state is true.

This feels like a hoisting issue as the issue is fixed if I use a function to wrap the isDisabled in the disabled setup (see comments).

Another way to fix it would be to move the isDisabled signal before the form initialization.

I probably would have expected ts to give this error:
Property 'isDisabled' is used before its initialization
which I have seen appear when a similar setup is used with likedSignal source, and the linkedSignal correctly warns about the issue.

import { Component, signal } from '@angular/core';
import { disabled, Field, form } from '@angular/forms/signals';

@Component({
  selector: 'swv-root',
  imports: [Field],
  styles: `
  input[disabled]{
    background-color: gray;
  }
  `,
  template: `
  <input [field]="componentForm.a" > 
  <div>
    should be disabled?: {{isDisabled()}}
  </div>
  <div>
    is really disabled?: {{componentForm.a().disabled()}}
  </div>
  `,
})
export class App {
  formModel = signal<{ a: string }>({ a: 'hello' });
  componentForm = form(this.formModel, (s) => {
    // disabled(s.a, () => this.isDisabled()); // << this work
    disabled(s.a, this.isDisabled); // << this doesnt work
  });
  isDisabled = signal(false);
}

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)


Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions