Skip to content

Implement mechanism to setup equals function on signal form's schema function. #69928

Description

@robmv

Which @angular/* package(s) are relevant/related to the feature request?

forms

Description

Currently there is no way to setup form fields of signal forms with the equality function they must be using. This is not a problem for controls since they can use any kind of equality mechanism to detect if the control value need to be updated or not.

The problem exist with fields programmatic value updates like:

form.date().value.set(Temporal.Now.plainDateISO());

Other signals have an option for the equality function, but it is missing from signal form fields. Every code that update the value needs to compare with the previous one, maybe using update(...)

This is not a new problem, because reactive FormControl, do not have a notion of equality functions either. But it could be a great improvement.

Proposed solution

Add new functions usable in the form schema function to setup the equality used by these fields

myform = form(this.contactModel, (schemaPath) => {
  required(schemaPath.date);
  equality(schemaPath.date, (a,b) => /* comparison l*/);
});

Notice these are not JS Date but PlainDate where Temporal.Now.plainDateISO() == Temporal.Now.plainDateISO() is false because they are objects.

Alternatives considered

Continue using update(...) manually on each programmatic update, but there are situations when you do not have control over who uses the signal, like passing a signal to other components, expecting them to update the field value. They have no way to know if the signal they get is a one normal writable signal with a proper equality function or if it is a form field, and really they should not be trying to distinguish.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status
    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions