Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
fix(signing): accept a dropdown choice that is wider than its box
RayFernando1337e573fc09eaf1
diff --git a/src/lib/long-text-field.dbtest.ts b/src/lib/long-text-field.dbtest.tsindex 3377754..edf2399 100644--- a/src/lib/long-text-field.dbtest.ts+++ b/src/lib/long-text-field.dbtest.ts@@ -210,3 +210,118 @@ test("an answer too long for its box is refused, one that wraps to fit is taken"await sign(answer);assert.deepEqual(await readState(), { status: "signed", value: answer });});++test("a dropdown choice wider than its box is taken, since the signer cannot shorten it", async () => {+ const userId = randomUUID();+ const envelopeId = randomUUID();+ const rileyId = randomUUID();+ const caseyId = randomUUID();+ const signatureId = randomUUID();+ const dropdownId = randomUUID();+ const now = unixNow();+ const link = await issueSigningLink({ expiresInSeconds: 60, issuedAt: now });+ const choices = [+ "Approved with the conditions listed in the schedule",+ "Rejected until the landlord answers the open questions",+ ];++ createdUsers.push(userId);+ await database.query(+ `insert into public."user" (id, name, email, role) values ($1, 'Sam Sender', $2, 'user')`,+ [userId, `${userId}@example.test`],+ );+ await database.query(+ `+ insert into envelopes (+ id, user_id, title, status, source_pdf_key, source_pdf_filename,+ source_pdf_size_bytes, page_count, source_pdf_hash, sent_at+ ) values ($1, $2, 'Lease', 'sent', $3, 'lease.pdf', 10, 1, $4, $5)+ `,+ [envelopeId, userId, `test/${envelopeId}.pdf`, "a".repeat(64), now],+ );+ await database.query(+ `+ insert into envelope_pages (id, envelope_id, page_number, width_pt, height_pt)+ values ($1, $2, 1, 612, 792)+ `,+ [randomUUID(), envelopeId],+ );+ await database.query(+ `+ insert into signers (+ id, envelope_id, name, email, sign_order, status,+ signing_token_hash, signing_token_expires_at, last_notified_at+ ) values ($1, $2, 'Riley Recipient', $3, 1, 'notified', $4, $5, $6)+ `,+ [+ rileyId,+ envelopeId,+ `${rileyId}@example.test`,+ link.tokenHash,+ link.exp,+ now,+ ],+ );+ await database.query(+ `+ insert into signers (id, envelope_id, name, email, sign_order, status)+ values ($1, $2, 'Casey Second', $3, 2, 'pending')+ `,+ [caseyId, envelopeId, `${caseyId}@example.test`],+ );+ // A required dropdown in a box too small for any of its choices.+ await database.query(+ `+ insert into fields (+ id, envelope_id, signer_id, type, page, x, y, width, height, options+ ) values+ ($1, $3, $4, 'signature', 1, 0.1, 0.1, 0.2, 0.1, null),+ ($2, $3, $4, 'dropdown', 1, 0.6, 0.3, 0.05, 0.012, $5)+ `,+ [signatureId, dropdownId, envelopeId, rileyId, JSON.stringify(choices)],+ );+ await recordSignerConsent(+ link.token,+ { disclosureVersion: ELECTRONIC_RECORDS_DISCLOSURE_VERSION },+ { database },+ );++ for (const choice of choices) {+ const fit = await checkSigningFieldFit(+ link.token,+ { fieldId: dropdownId, value: choice },+ { database },+ );++ assert.equal(fit.fits, false);+ }++ await submitSigningForToken(+ link.token,+ {+ clientTimezoneOffsetMinutes: 0,+ fields: [+ {+ fieldId: signatureId,+ inputMethod: "typed",+ type: "signature",+ value: "Riley Recipient",+ },+ { fieldId: dropdownId, type: "dropdown", value: choices[0] },+ ],+ },+ { database, emailService, storageService },+ );++ const field = await database.query<{ value: string | null }>(+ `select value from fields where id = $1`,+ [dropdownId],+ );+ const signer = await database.query<{ status: string }>(+ `select status from signers where id = $1`,+ [rileyId],+ );++ assert.equal(field.rows[0]?.value, choices[0]);+ assert.equal(signer.rows[0]?.status, "signed");+});diff --git a/src/lib/services/pdf-finalize.ts b/src/lib/services/pdf-finalize.tsindex e0a9277..52d6fe2 100644--- a/src/lib/services/pdf-finalize.ts+++ b/src/lib/services/pdf-finalize.ts@@ -784,8 +784,9 @@ async function drawFieldValue(}// Wrapped and made smaller until the whole value is inside the box.- // Signing refuses a value that would only fit below a readable size,- // but one accepted earlier is still drawn whole, never cut off.+ // Signing refuses a typed value that would only fit below a readable+ // size, but a dropdown choice, or a value accepted earlier, is still+ // drawn whole, never cut off.const box = getTextFieldBox(rect);let layout = layoutFieldText(fonts.auditRegular,diff --git a/src/lib/signing.ts b/src/lib/signing.tsindex 16a307d..815a574 100644--- a/src/lib/signing.ts+++ b/src/lib/signing.ts@@ -2275,7 +2275,9 @@ type SigningContext = Awaited<ReturnType<typeof resolveSigningContext>>;/*** Refuses an answer too long to be read in its box on the finished document,* before anything is saved, so the signer can shorten it. Without this the- * value would be drawn so small that no one could read it.+ * value would be drawn so small that no one could read it. A dropdown choice+ * is the sender's text, which the signer cannot shorten, so it is taken and+ * drawn whole however small.*/async function assertTypedValuesFitTheirFields(context: SigningContext,@@ -2284,10 +2286,7 @@ async function assertTypedValuesFitTheirFields(const entries = context.fields.flatMap((field) => {const value = field.id ? fieldUpdates.get(field.id)?.value : null;- return (field.type === "text" ||- field.type === "number" ||- field.type === "dropdown") &&- value+ return (field.type === "text" || field.type === "number") && value? [{ field, value }]: [];});