MCPcopy Create free account
hub / github.com/LibPDF-js/core / setValue

Method setValue

src/document/forms/fields/checkbox-field.ts:99–122  ·  view source on GitHub ↗

* Set the checkbox value. * * This method is async because it regenerates the field's appearance * stream after setting the value. * * @param value "Off" or one of the on-values * @throws {Error} if field is read-only or value is invalid

(value: string)

Source from the content-addressed store, hash-verified

97 * @throws {Error} if field is read-only or value is invalid
98 */
99 setValue(value: string): void {
100 this.assertWritable();
101
102 // Validate value
103 if (value !== "Off" && !this.getOnValues().includes(value)) {
104 throw new Error(`Invalid value "${value}" for checkbox "${this.name}"`);
105 }
106
107 // Set /V on field
108 this.dict.set("V", PdfName.of(value));
109
110 // Update /AS on each widget
111 for (const widget of this.getWidgets()) {
112 const widgetOnValue = widget.getOnValue();
113 const state = widgetOnValue === value ? value : "Off";
114
115 widget.setAppearanceState(state);
116 }
117
118 this.needsAppearanceUpdate = true;
119
120 // Regenerate appearance immediately
121 this.applyChange();
122 }
123}

Callers 2

checkMethod · 0.95
uncheckMethod · 0.95

Calls 6

getOnValuesMethod · 0.95
getWidgetsMethod · 0.80
setAppearanceStateMethod · 0.80
setMethod · 0.45
ofMethod · 0.45
getOnValueMethod · 0.45

Tested by

no test coverage detected