MCPcopy Index your code
hub / github.com/OpenSignLabs/OpenSign / isWidgetResponseCompatible

Function isWidgetResponseCompatible

apps/OpenSign/src/utils/widgetUtils.js:411–460  ·  view source on GitHub ↗
(widget, newResponse = "")

Source from the content-addressed store, hash-verified

409}
410
411export const isWidgetResponseCompatible = (widget, newResponse = "") => {
412 const { type, options } = widget;
413 const response = newResponse || options?.response;
414
415 // If no response → skip only when widget truly needs it
416 if (response === undefined || response === null) {
417 return false;
418 }
419
420 switch (type) {
421 // 🖼 Image widgets → valid base64 only
422 case "signature":
423 case "stamp":
424 case "initials":
425 case "image":
426 case drawWidget:
427 return typeof response === "string" && isBase64(response);
428
429 // ☑ Checkbox → array of indexes
430 case "checkbox":
431 return (
432 Array.isArray(response) && response.every((i) => Number.isInteger(i))
433 );
434
435 // 🔘 Radio → must exist in options
436 case radioButtonWidget:
437 return options?.values?.some((val) => val?.trim() === response?.trim());
438
439 // 📅 Date → valid date or "today"
440 case "date":
441 return response === "today" || !isNaN(new Date(response).getTime());
442
443 // ⬇ Dropdown → must match options
444 case "dropdown":
445 return options?.values?.some((val) => val?.trim() === response?.trim());
446
447 // 📝 Text widgets
448 case textWidget:
449 case textInputWidget:
450 case cellsWidget:
451 case "name":
452 case "company":
453 case "job title":
454 case "email":
455 return typeof response === "string" || typeof response === "number";
456
457 default:
458 return true;
459 }
460};
461export const formatCSVDate = (widget, response, formatInISO = false) => {
462 const format = widget?.options?.validation?.format ?? "dd-MM-yyyy";
463 const input = response === "today" ? new Date() : response;

Callers 1

updateWidgetValuesFunction · 0.90

Calls 1

isBase64Function · 0.90

Tested by

no test coverage detected