The appointment owner disappears from a reactive form payloa


Topic: The appointment owner disappears from a reactive form payload

Maya Fischer asked a week ago

An appointment editor shows the selected owner's name but does not allow it to be changed. We disable ownerId on the reactive form, and the dropdown correctly appears unavailable.

When saving, the request is built from form.value. It includes title and location but does not include ownerId, even though the control still contains the correct ID. Should we enable the field temporarily to collect that value?


Disabled controls are omitted from an enabled FormGroup's value. You do not need to toggle the control just to read it: getRawValue includes disabled controls, or you can read ownerId directly and construct the payload explicitly.

Keep the server-side permission check for the owner field. A disabled client-side control is a user-interface choice, so the endpoint should still validate which owner the signed-in person is allowed to submit. Use only the fields required by the request contract.

const raw = this.form.getRawValue();
const payload = {
  title: raw.title,
  location: raw.location,
  ownerId: raw.ownerId
};

https://mdbootstrap.com/docs/angular/plugins/calendar/


Maya Fischer commented 7 days ago

getRawValue contains ownerId now, but the network request still omits it. I followed the request into our service and found a second mapping step. This is the whole payload mapper before HttpClient posts it.

toRequest(value: AppointmentFormValue) {
  return {
    title: value.title,
    location: value.location
  };
}

Arkadiusz Idzikowski staff commented 6 days ago

That second mapper is dropping the owner after the form has provided it correctly. Include ownerId in the request object there, and keep the request interface aligned with what the endpoint expects.

Log the final mapped object or inspect the network payload after this change. You can leave the form control disabled; collecting the raw value and preserving the field through the mapper are separate steps.

toRequest(value: AppointmentFormValue) {
  return {
    title: value.title,
    location: value.location,
    ownerId: value.ownerId
  };
}

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: MDB5 9.1.0
  • Device: Laptop
  • Browser: Chrome
  • OS: Ubuntu
  • Provided sample code: No
  • Provided link: No