Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing documentation for controlsConfig argument of FormBuilder.group method #43984

Open
slavafomin opened this issue Oct 29, 2021 · 2 comments
Open

Comments

@slavafomin
Copy link

@slavafomin slavafomin commented Oct 29, 2021

Description

The documentation for FormBuilder.group() method lacks proper description of the controlsConfig argument.

It is described the following way:

A collection of child controls. The key for each child is the name under which it is registered.

and is typed this way: { [key: string]: any; }.

However, it's not clear what is the interface of the object values. The typing declarations are also missing in the code of this method.


I can't figure out how to use updateOn, value and disabled options at the same time with the form builder and it's not possible to understand from the documentation or type declarations.

What is the affected URL?

https://angular.io/api/forms/FormBuilder#group

Please provide the steps to reproduce the issue

No response

Please provide the expected behavior vs the actual behavior you encountered

No response

Please provide a screenshot if possible

No response

Please provide the exception or error you saw

No response

Is this a browser-specific issue? If so, please specify the device, browser, and version.

No response

@slavafomin
Copy link
Author

@slavafomin slavafomin commented Oct 29, 2021

By the way, the correct way to use both disabled and updateOn is the following:

  formBuilder.group({
    foo: [
      {
        value: 'Foo',
        disabled: true,
      },
      {
        updateOn: 'blur',
      },
    ],
  });

However, it was quite unintuitive to figure out. The fact that you have to use an array with two objects is just incomprehensible.

I would suggest to update the documentation to make this case explicit and I would also suggest to update the API and typing declarations as well to make it more straightforward to use.

@slavafomin
Copy link
Author

@slavafomin slavafomin commented Oct 29, 2021

Also, the code here is just misleading:

const validator: ValidatorFn = controlConfig.length > 1 ? controlConfig[1] : null;

It should be:

const validatorOrOpts: (
  | ValidatorFn
  | ValidatorFn[]
  | AbstractControlOptions
  | null
  
) = (controlConfig[1] || null);

because the second argument could be either validator, array of validators or an options object.

@ngbot ngbot bot added this to the needsTriage milestone Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants