Browse Source

Merge pull request #8041 from timvandermeij/radio-button-value

Interactive forms: set the `buttonValue` for radio buttons that do not have a `fieldValue`
Tim van der Meij 8 years ago committed by GitHub
parent
commit
35102c025a
  1. 10
      src/core/annotation.js
  2. 28
      test/unit/annotation_spec.js

10
src/core/annotation.js

@ -786,14 +786,12 @@ var ButtonWidgetAnnotation = (function ButtonWidgetAnnotationClosure() {
// The parent field's `V` entry holds a `Name` object with the appearance // The parent field's `V` entry holds a `Name` object with the appearance
// state of whichever child field is currently in the "on" state. // state of whichever child field is currently in the "on" state.
var fieldParent = params.dict.get('Parent'); var fieldParent = params.dict.get('Parent');
if (!isDict(fieldParent) || !fieldParent.has('V')) { if (isDict(fieldParent) && fieldParent.has('V')) {
return;
}
var fieldParentValue = fieldParent.get('V'); var fieldParentValue = fieldParent.get('V');
if (!isName(fieldParentValue)) { if (isName(fieldParentValue)) {
return;
}
this.data.fieldValue = fieldParentValue.name; this.data.fieldValue = fieldParentValue.name;
}
}
// The button's value corresponds to its appearance state. // The button's value corresponds to its appearance state.
var appearanceStates = params.dict.get('AP'); var appearanceStates = params.dict.get('AP');

28
test/unit/annotation_spec.js

@ -988,7 +988,7 @@ describe('annotation', function() {
expect(data.radioButton).toEqual(false); expect(data.radioButton).toEqual(false);
}); });
it('should handle radio buttons', function() { it('should handle radio buttons with a field value', function() {
var parentDict = new Dict(); var parentDict = new Dict();
parentDict.set('V', Name.get('1')); parentDict.set('V', Name.get('1'));
@ -1017,6 +1017,32 @@ describe('annotation', function() {
expect(data.fieldValue).toEqual('1'); expect(data.fieldValue).toEqual('1');
expect(data.buttonValue).toEqual('2'); expect(data.buttonValue).toEqual('2');
}); });
it('should handle radio buttons without a field value', function() {
var normalAppearanceStateDict = new Dict();
normalAppearanceStateDict.set('2', null);
var appearanceStatesDict = new Dict();
appearanceStatesDict.set('N', normalAppearanceStateDict);
buttonWidgetDict.set('Ff', AnnotationFieldFlag.RADIO);
buttonWidgetDict.set('AP', appearanceStatesDict);
var buttonWidgetRef = new Ref(124, 0);
var xref = new XRefMock([
{ ref: buttonWidgetRef, data: buttonWidgetDict, }
]);
var annotation = annotationFactory.create(xref, buttonWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(false);
expect(data.radioButton).toEqual(true);
expect(data.fieldValue).toEqual(null);
expect(data.buttonValue).toEqual('2');
});
}); });
describe('ChoiceWidgetAnnotation', function() { describe('ChoiceWidgetAnnotation', function() {

Loading…
Cancel
Save