* Remove a form field from the document. * * This removes the field from the AcroForm and all its widget annotations * from their respective pages. * * @param fieldOrName - The field instance or field name to remove * @returns true if the field was found and removed, false otherwis
(fieldOrName: FormField | string)
| 1008 | * ``` |
| 1009 | */ |
| 1010 | removeField(fieldOrName: FormField | string): boolean { |
| 1011 | // Resolve field from name if needed |
| 1012 | const field = |
| 1013 | typeof fieldOrName === "string" ? this.fieldsByName.get(fieldOrName) : fieldOrName; |
| 1014 | |
| 1015 | if (!field) { |
| 1016 | return false; |
| 1017 | } |
| 1018 | |
| 1019 | const fieldRef = field.getRef(); |
| 1020 | |
| 1021 | if (!fieldRef) { |
| 1022 | return false; |
| 1023 | } |
| 1024 | |
| 1025 | // Remove widgets from their pages |
| 1026 | this.removeWidgetsFromPages(field); |
| 1027 | |
| 1028 | // Remove field from AcroForm's /Fields array |
| 1029 | const removed = this._acroForm.removeField(fieldRef); |
| 1030 | |
| 1031 | if (removed) { |
| 1032 | // Update internal caches |
| 1033 | this.allFields = this.allFields.filter(f => f !== field); |
| 1034 | this.fieldsByName.delete(field.name); |
| 1035 | } |
| 1036 | |
| 1037 | return removed; |
| 1038 | } |
| 1039 | |
| 1040 | /** |
| 1041 | * Remove all widgets of a field from their respective pages. |
no test coverage detected