Validation

Run audits on designs to catch missing links, empty content, accessibility issues, and custom business rules before sending.

React
tsx


function ValidatedEditor() {
  const editorRef = useRef<DragbleEditorRef>(null);

  const runAudit = async () => {
    const result = await editorRef.current?.editor?.audit();
    if (result?.status === "PASS") {
      console.log("Design is valid — ready to send");
    } else {
      console.warn("Audit failed:", result?.errors);
      // [{ type: 'MISSING_UNSUBSCRIBE', message: '...', severity: 'error', rowId: '...' }]
    }
  };

  return (
    <>
      <DragbleEditor
        ref={editorRef}
        editorKey="db_your_key"
        editorMode="email"
      />
      <button onClick={runAudit}>Validate</button>
    </>
  );
}
Vue
plaintext
<template>
  <DragbleEditor ref="editorRef" editor-key="db_your_key" editor-mode="email" />
  <button @click="runAudit">Validate</button>
</template>

<script setup lang="ts">


const editorRef = ref<InstanceType<typeof DragbleEditor>>();

async function runAudit() {
  const result = await editorRef.value?.audit();
  if (result?.status === "PASS") {
    console.log("Design is valid");
  } else {
    console.warn("Issues found:", result?.errors);
  }
}
</script>
Angular
typescript



@Component({
  selector: "app-validated-editor",
  standalone: true,
  imports: [DragbleEditorComponent],
  template: `
    <dragble-editor
      #editor
      editorKey="db_your_key"
      editorMode="email"
      (ready)="onReady($event)"
    ></dragble-editor>
    <button (click)="runAudit()">Validate</button>
  `,
})
export class ValidatedEditorComponent {
  @ViewChild("editor") editorComp!: DragbleEditorComponent;
  private sdk: DragbleSDK | null = null;

  onReady(sdk: DragbleSDK) {
    this.sdk = sdk;
  }

  async runAudit() {
    const result: AuditResult | undefined = await this.sdk?.audit();
    console.log(result?.status, result?.errors);
  }
}
Vanilla JS
typescript
const result = await dragble.audit();

if (result.status === "PASS") {
  console.log("All checks passed");
} else {
  result.errors.forEach((err) => {
    console.warn(`[${err.severity}] ${err.type}: ${err.message}`);
  });
}

Custom validators

Add your own validation rules with setValidator(). The validator function receives the design JSON and returns an array of errors:

typescript
dragble.setValidator(async (design) => {
  const errors = [];

  // Check for subject line
  if (!design.metadata?.subject) {
    errors.push({
      type: "MISSING_SUBJECT",
      message: "Email subject line is required",
      severity: "error",
    });
  }

  // Check minimum content
  if (design.rows.length < 2) {
    errors.push({
      type: "INSUFFICIENT_CONTENT",
      message: "Design should have at least 2 content rows",
      severity: "warning",
    });
  }

  return errors;
});
Severity levels

Use 'error' for issues that must be fixed before sending, and 'warning' for suggestions. Only error severity causes audit() to return status: 'FAIL'.

Validate without UI

Use validateTemplate() for server-side or headless validation that does not highlight errors in the editor:

typescript
const result = await dragble.validateTemplate(designJson);
// Same AuditResult shape, but no visual indicators in the editor
Built-in checks

The default audit checks for: missing unsubscribe link, empty alt text on images, broken merge tags, empty content rows, and oversized images. Custom validators run in addition to these.

AuditResult type

typescript
interface AuditResult {
  status: "PASS" | "FAIL";
  errors: Array<{
    type: string;
    message: string;
    severity: "error" | "warning";
    rowId?: string;
  }>;
}

Method reference

MethodReturnsDescription
audit()Promise<AuditResult>Run all validators and highlight issues in the editor
setValidator(fn)voidRegister a custom validation function
validateTemplate(json)Promise<AuditResult>Validate a design JSON without editor UI

Next steps