@hubsync/esign-web-sdk 6.5.4 → 6.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -390,6 +390,8 @@ const VerdocsSign = class {
390
390
  if (e.detail === null) {
391
391
  console.log('[SIGN] Clearing initial');
392
392
  const updateResult = await jsSdk.updateEnvelopeField(this.endpoint, this.envelopeId, this.roleId, field.name, null, false);
393
+ updateResult.value = null;
394
+ this.initialId = null;
393
395
  return this.updateRecipientFieldValue(field.name, updateResult);
394
396
  }
395
397
  // If we already have an initials block, apply it
@@ -430,6 +432,8 @@ const VerdocsSign = class {
430
432
  if (e.detail === null) {
431
433
  console.log('[SIGN] Clearing signature');
432
434
  const updateResult = await jsSdk.updateEnvelopeField(this.endpoint, this.envelopeId, this.roleId, field.name, null, false);
435
+ updateResult.value = null;
436
+ this.signatureId = null;
433
437
  return this.updateRecipientFieldValue(field.name, updateResult);
434
438
  }
435
439
  // If we already have a signature block, apply it
@@ -499,13 +503,13 @@ const VerdocsSign = class {
499
503
  }
500
504
  return;
501
505
  }
502
- const nextRequiredField = this.getNextRequiredField();
503
- if (nextRequiredField) {
504
- const id = utils.getFieldId(nextRequiredField);
506
+ const nextField = this.getNextFieldInOrder();
507
+ if (nextField) {
508
+ const id = utils.getFieldId(nextField);
505
509
  const el = document.getElementById(id);
506
510
  el === null || el === void 0 ? void 0 : el.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
507
511
  el === null || el === void 0 ? void 0 : el.focusField();
508
- this.focusedField = nextRequiredField.name;
512
+ this.focusedField = nextField.name;
509
513
  }
510
514
  }
511
515
  getRecipientFields() {
@@ -527,24 +531,36 @@ const VerdocsSign = class {
527
531
  }
528
532
  this.updateAllFlags();
529
533
  }
530
- getNextRequiredField() {
531
- // Find and focus the next incomplete field (that is fillable)
532
- const emptyFields = this.getSortedFillableFields().filter(field => field.required && !jsSdk.isFieldFilled(field, this.getRecipientFields()));
533
- jsSdk.sortFields(emptyFields);
534
- // console.log(
535
- // '[SIGN] Pending fields',
536
- // emptyFields.map(f => `${f.name} (${f.type}) req=${f.required}`),
537
- // );
538
- if (emptyFields.length === 0) {
539
- const allUnfilled = this.getSortedFillableFields().filter(field => !jsSdk.isFieldFilled(field, this.getRecipientFields()));
540
- jsSdk.sortFields(allUnfilled);
541
- if (allUnfilled.length > 0) {
542
- // If we are here, there are no required fields left, but there are optional ones.
543
- return this.getNextFieldFromList(allUnfilled);
544
- }
534
+ getNextFieldInOrder() {
535
+ // Find the next incomplete field in overall order (required + optional).
536
+ const fields = this.getSortedFillableFields();
537
+ if (fields.length === 0)
545
538
  return null;
539
+ const recipientFields = this.getRecipientFields();
540
+ const focusedIndex = fields.findIndex(field => field.name === this.focusedField);
541
+ const startIndex = focusedIndex >= 0 ? focusedIndex + 1 : 0;
542
+ for (let i = 0; i < fields.length; i++) {
543
+ const idx = (startIndex + i) % fields.length;
544
+ const field = fields[idx];
545
+ if (!this.isFieldFilledForNav(field, recipientFields)) {
546
+ return field;
547
+ }
548
+ }
549
+ return null;
550
+ }
551
+ isFieldFilledForNav(field, recipientFields) {
552
+ if (field.type === 'signature' || field.type === 'initial') {
553
+ const value = typeof field.value === 'string' ? field.value.trim() : field.value;
554
+ if (!value)
555
+ return false;
556
+ if (value === 'signed' || value === 'initialed')
557
+ return false;
558
+ return true;
559
+ }
560
+ if (field.type === 'dropdown') {
561
+ return jsSdk.isFieldFilled(field, recipientFields) && !!field.value;
546
562
  }
547
- return this.getNextFieldFromList(emptyFields);
563
+ return jsSdk.isFieldFilled(field, recipientFields);
548
564
  }
549
565
  getNextFieldFromList(fields) {
550
566
  const focusedIndex = fields.findIndex(field => field.name === this.focusedField);
@@ -582,12 +598,12 @@ const VerdocsSign = class {
582
598
  // Remove existing flags
583
599
  const existingFlags = controlsDiv.querySelectorAll('.verdocs-flag-instance');
584
600
  existingFlags.forEach(el => el.remove());
585
- let nextField = this.getNextRequiredField();
601
+ let nextField = this.getNextFieldInOrder();
586
602
  const focusedFieldObj = this.getRecipientFields().find(f => f.name === this.focusedField);
587
603
  // If the currently focused field is unfilled, we should point the flag to IT, not the next one.
588
- // getNextRequiredField() is designed for the "Next" button (skipping current), but the visual flag
604
+ // getNextFieldInOrder() is designed for the "Next" button (skipping current), but the visual flag
589
605
  // should guide the user to the current task if it's incomplete.
590
- if (focusedFieldObj && !jsSdk.isFieldFilled(focusedFieldObj, this.getRecipientFields())) {
606
+ if (focusedFieldObj && !this.isFieldFilledForNav(focusedFieldObj, this.getRecipientFields())) {
591
607
  nextField = focusedFieldObj;
592
608
  }
593
609
  if (nextField && nextField.page === pageInfo.pageNumber && nextField.document_id === pageInfo.documentId) {