parallax/jsPDF · error · Error

Couldn't assign Appearance to RadioButton. Appearance was In

Error message

Couldn't assign Appearance to RadioButton. Appearance was Invalid!

What it means

AcroFormRadioButton.setAppearance() accepts a custom appearance object to change how radio button options are rendered (e.g., Circle vs Cross style). The appearance object must implement two methods: createAppearanceStream(optionName) which returns the appearance dictionary, and getCA() which returns the caption character. This is a duck-typing check — the library does not use instanceof. The built-in valid appearances are AcroFormAppearance.RadioButton.Circle and AcroFormAppearance.RadioButton.Cross.

Source

Thrown at src/modules/acroform.js:2345

      }
      _AS = "/" + pdfEscapeName(name);
    }
  });
  this.caption = "l";
  this.appearanceState = "Off";
  // todo: set AppearanceType as variable that can be set from the
  // outside...
  this._AppearanceType = AcroFormAppearance.RadioButton.Circle;
  // The Default appearanceType is the Circle
  this.appearanceStreamContent = this._AppearanceType.createAppearanceStream(
    this.optionName
  );
};
inherit(AcroFormChildClass, AcroFormField);

AcroFormRadioButton.prototype.setAppearance = function(appearance) {
  if (!("createAppearanceStream" in appearance && "getCA" in appearance)) {
    throw new Error(
      "Couldn't assign Appearance to RadioButton. Appearance was Invalid!"
    );
  }
  for (var objId in this.Kids) {
    if (this.Kids.hasOwnProperty(objId)) {
      var child = this.Kids[objId];
      child.appearanceStreamContent = appearance.createAppearanceStream(
        child.optionName
      );
      child.caption = appearance.getCA();
    }
  }
};

AcroFormRadioButton.prototype.createOption = function(name) {
  // Create new Child for RadioGroup
  var child = new AcroFormChildClass();
  child.Parent = this;

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Use a built-in appearance: radioButton.setAppearance(AcroFormAppearance.RadioButton.Cross) or AcroFormAppearance.RadioButton.Circle
  2. If building a custom appearance, ensure it has both createAppearanceStream(name) and getCA() methods
  3. Verify the appearance object with a type guard before calling setAppearance
  4. Do not pass appearances designed for CheckBox or PushButton fields to a RadioButton

Example fix

// before
radioButton.setAppearance({ custom: true }); // throws
radioButton.setAppearance(AcroFormAppearance.CheckBox); // throws - no getCA

// after
radioButton.setAppearance(AcroFormAppearance.RadioButton.Cross);
Defensive patterns

Strategy: type-guard

Validate before calling

// Check appearance object before calling setAppearance
function isValidAppearance(obj) {
  return obj !== null &&
    typeof obj === 'object' &&
    typeof obj.createAppearanceStream === 'function' &&
    typeof obj.getCA === 'function';
}

if (isValidAppearance(myAppearance)) {
  radioButton.setAppearance(myAppearance);
}

Type guard

/**
 * @param {*} appearance
 * @returns {boolean}
 */
function isRadioButtonAppearance(appearance) {
  return typeof appearance === 'object' && appearance !== null &&
    'createAppearanceStream' in appearance &&
    'getCA' in appearance;
}

Try / catch

try {
  radioButton.setAppearance(customAppearance);
} catch (e) {
  // Fall back to built-in appearance
  radioButton.setAppearance(jsPDF.AcroFormAppearance.RadioButton.Circle);
}

Prevention

When it happens

Trigger: Calling radioButton.setAppearance(someObject) where someObject lacks createAppearanceStream or getCA methods. Passing AcroFormAppearance.CheckBox (which has a different createAppearanceStream signature and no getCA). Passing a plain object literal or a partially constructed appearance.

Common situations: Developers trying to use a CheckBox appearance on a RadioButton, or constructing a custom appearance object without implementing both required methods. Copy-pasting appearance objects from examples that target different field types.

Related errors


AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13). Data as JSON: /api/errors/04e436b4f0fe4671. Report an issue: GitHub.