Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed radio/checkbox return values in getAllFieldsTypes() #383

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/pdffield.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,30 @@ export default class PDFField {
//static public method to generate fieldsType object based on parser result
static getAllFieldsTypes(data) {
const isFieldReadOnly = field => (field.AM & kFBANotOverridable) ? true : false;

function getFieldValue(field) {
switch(field.T.Name) {
case 'box':
return field.checked === undefined ? false : field.checked;
case 'alpha':
case 'date':
default:
return field.V;
}
}
const getFieldBase = field => ({
id: field.id.Id,
type: field.T.Name,
calc: isFieldReadOnly(field),
value: field.V || ""
value: getFieldValue(field)
});

const retVal = [];
data.Pages.forEach( page => {
page.Boxsets.forEach( boxsets => {
if (boxsets.boxes.length > 1) { //radio button
boxsets.boxes.forEach( box => {
if(box.checked)
retVal.push({ id: boxsets.id.Id, type: "radio", calc: isFieldReadOnly(box), value: box.id.Id });
});
}
Expand Down