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

How to set only a single FormControl to disabled. #253

Open
ChrTall opened this issue Apr 27, 2022 · 1 comment
Open

How to set only a single FormControl to disabled. #253

ChrTall opened this issue Apr 27, 2022 · 1 comment
Labels
type: RFC/discussion/question This issue is about RFC, discussion or a question

Comments

@ChrTall
Copy link

ChrTall commented Apr 27, 2022

I have a form with a field in the form model that should not be changed by the user and is filled automatically for create forms.
I would still like to display this field to the user, but disable the input.

I tried the following, but the readOnlyProperty is still editable.

public baseForm = createForm<Entity, EntityFormModel>(this, { formType: FormType.ROOT, disabled$: this.disabled$, input$: this.input$, output$: this.updatedEntity, manualSave$: this.manualSave$, formControls: ChartFormComponent.getFormControls(), toFormGroup: (obj: Entity): EntityFormModel => { return mapEntityToEntityFormModel(obj); }, fromFormGroup: (formValue: EntityFormModel): EntityUnion => { return mapEntityFormModelToEntity(formValue); } });

private static getFormControls(): Controls<EntityFormModel> { return { // Should be disabled, but still shown to the user. readOnlyProperty: new FormControl({disabled: true}), discriminator: new FormControl(null), // Should and is editable. property: new FormControl(null) } }

@maxime1992
Copy link
Contributor

Yup I think this relates to a known issue with Angular on which I gave my input here: angular/angular#11447 (comment)

I think your best move for now is to either

simply display it without using an input (and therefore no need to make it disabled)

OR

Disable the input then use the remap function in the create form to read the value using the raw attribute or function on the form (can't remember on top of my head right now) and pass that instead of the classic form value that ngx sub form uses by default.

Hopefully that makes sense, I replied quite quickly, if it doesn't let me know

@maxime1992 maxime1992 added the type: RFC/discussion/question This issue is about RFC, discussion or a question label Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: RFC/discussion/question This issue is about RFC, discussion or a question
Projects
None yet
Development

No branches or pull requests

2 participants