How does lightning-record-edit-form enable granular field-level customization during record creation and editing?
Answer
Basics: Unlike lightning-record-form (auto layout) and lightning-record-view-form (read-only), the edit form lets you pick exactly which fields to show, in any markup. Set object-api-name, add record-id to edit (omit to create), place lightning-input-field field-name="Name" components and a submit button. Labels, required flags, picklist values and lookups come from metadata automatically.
How it works: Clicking a lightning-button type="submit" fires onsubmit. If you do nothing it saves the field values. To customize, call event.preventDefault(), read or modify event.detail.fields, then call this.template.querySelector('lightning-record-edit-form').submit(fields). Other events: onload, onsuccess (event.detail.id), onerror (event.detail), and lightning-messages displays server and validation errors. lightning-output-field can be placed inside to display read-only values.
Advanced / deep dive: It uses Lightning Data Service and UI API, so it enforces object CRUD, field-level security and sharing, runs validation rules and triggers on the server, and updates the LDS cache so other components on the page refresh. Custom validation: server-side validation rules are the source of truth; client-side checks belong in onsubmit (cross-field rules, then preventDefault and show your own error) or via reportValidity() on fields. Defaults for create can be set with value on input fields. It handles one record; for related-record writes or transactional multi-object saves use Apex. Not all field types or compound fields behave the same in ; test addresses, rich text and polymorphic lookups. Dynamic forms in the App Builder are the declarative alternative for layout control without code.