الانتقال إلى المحتوى
FrontendAngular· 7 دقائق للقراءة

Why form.value Is Partial: Disabled Controls and getRawValue()

In Reactive Forms, a disabled control drops out of form.value. The Partial type is a warning, not noise: send getRawValue() when you need everything.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • Angular 22
محتويات المقال

The "Edit employee" page shows the email field greyed out once an account is verified, so nobody changes it by accident. A week after release, support reports that saving a verified employee fails with a 400 and the message "email is required". The Network panel shows the PUT body: {"name":"Mona Adel"}, no email at all. The save handler sends this.form.value as Employee, and the cast was added months earlier to make a TypeScript error go away. That error was the bug, reported before it shipped.

The common misconception

The belief: form.value is the form's data. Every control you declared in the FormGroup shows up in it, so it's the payload to send to the API as is.

For most forms, that's exactly what you see. When no control is disabled, form.value has every key, and logging it during development confirms the shape you expect. Even the examples in Angular's reactive forms guide pass this.form.value straight to a save call, because nothing in them is disabled. And for years before Angular 14, when reactive forms became strictly typed, most form APIs had any in their types, so nothing hinted that a key could go missing. When the type finally appeared, many teams read it as a quirk of the typings and cast it away.

What actually happens

value collects the enabled controls

A group computes its value from its children, and the FormGroup API docs are explicit about disabled children: they're excluded from the aggregate value of their ancestors. Disable the email control and form.value stops having an email key. Not null, not an empty string: the key isn't there. A FormArray follows the same rule: its value is an array of its enabled controls, so disabling the second of three rows gives you two elements, and every index after the disabled row shifts.

The type reflects that. The typed forms guide explains that because any control can be disabled at runtime, the type of login.value is Partial<{ email: string; password: string }>, so each member might be undefined. TypeScript can't know which controls you'll disable, so it makes you handle all of them. That's precisely the error the as Employee cast silenced.

getRawValue() collects everything

getRawValue() is the aggregate value including disabled controls, and its type is the full object with no Partial. It's the method the typed forms guide points to when you want every field and don't want to handle undefined.

That doesn't make value wrong. If your endpoint is a PATCH that should receive only what the user was allowed to edit, leaving the disabled controls out is exactly what you want. The two methods answer different questions, and the types tell you which one you asked.

TypeScript edit-employee.ts
import { Component, inject } from '@angular/core';import { NonNullableFormBuilder, ReactiveFormsModule } from '@angular/forms';@Component({  selector: 'app-edit-employee',  imports: [ReactiveFormsModule],  templateUrl: './edit-employee.html',})export class EditEmployee {  private readonly api = inject(EmployeeApi);  private readonly fb = inject(NonNullableFormBuilder);  readonly form = this.fb.group({    name: '',    email: { value: '', disabled: true },  });  save() {    // The cast hides Partial: the PUT body has no email    this.api.update(this.form.value as Employee).subscribe();  }}

The right version needs no cast: getRawValue() already has the shape of Employee, so the compiler checks it.

Nullable controls are a second gap

getRawValue() fills in the keys, but it doesn't remove null. A plain new FormControl('') is typed FormControl<string | null>, because calling reset() sets it to null. Created with { nonNullable: true }, a control resets to its initial value instead, and its type drops the null. NonNullableFormBuilder, used above, applies that option to every control it creates, which is why getRawValue() here matches Employee exactly.

Disabled also means unvalidated

A disabled control is exempt from validation checks, too. A required validator on a disabled, empty field won't make the form invalid, so form.valid can be true while the data is incomplete. And one detail surprises people: when the group itself is disabled, for example while a save is in flight, its value includes all of its controls again.

TypeScript value-shape.ts
import { FormControl, FormGroup } from '@angular/forms';const form = new FormGroup({  name: new FormControl('Mona'),  email: new FormControl({ value: 'mona@example.com', disabled: true }),});console.log(form.value); // { name: 'Mona' }form.disable();console.log(form.value); // { name: 'Mona', email: 'mona@example.com' }
form.valueform.getRawValue()
Disabled controlsLeft outIncluded
TypePartial<{ ... }>The full object
When the group is disabledAll controlsAll controls
Good forSending only editable fieldsThe complete payload

How to apply it in your project

  1. Search for casts on form valuesFind .value as and every form.value passed to an HTTP call. Where the form has disabled controls, switch to getRawValue(), or keep value and write down why the disabled fields must not be sent.
  2. Make controls non-nullableCreate forms with NonNullableFormBuilder or { nonNullable: true }, so getRawValue() matches your API types without null checks or casts.
  3. Don't trust form.valid for disabled fieldsDisabled controls aren't validated. If a disabled field must still be correct, check it before saving, and keep the server's validation as the final word.
  4. Test the disabled pathAdd a test that disables the conditional controls, submits, and asserts on the request body, so a missing key fails in CI instead of in production.

Key takeaways

  • In Reactive Forms, form.value contains only enabled controls, which is why its type is a Partial.
  • getRawValue() returns every control, disabled ones included, with a type that matches the full model.
  • Non-nullable controls remove the remaining null from the type; disabled controls also skip validation.
  • Signal Forms keep every field in your model signal, so the omission becomes your decision.

📚 المصادر

  1. Typed Forms — Angular
  2. FormGroup — Angular
  3. Reactive forms — Angular
  4. Adding form logic (Signal Forms) — Angular

التعليقات (0)