Skip to content

Multiple Schemas

Single Instance

vue
<script lang="ts" setup>
const fooSchema = useSchema(
  /* ... */
  toRef(state, 'fooForm'),
  toRef(state, 'myValdn'), 
);

const barSchema = useSchema(
  /* ... */
  toRef(state, 'barForm'),
  toRef(state, 'myValdn'), 
);

const fooSubmit = () => {
  barSchema.stop(); 

  if (fooSchema.validate()) {
    // passed
  }
};

const barSubmit = () => {
  fooSchema.stop(); 

  if (barSchema.validate()) {
    // passed
  }
};
</script>

Multiple Instances

vue
<script lang="ts" setup>
const fooSchema = useSchema(
  /* ... */
  toRef(state, 'fooForm'),
  toRef(state, 'fooValdn'), 
);

const barSchema = useSchema(
  /* ... */
  toRef(state, 'barForm'),
  toRef(state, 'barValdn'), 
);

const fooSubmit = () => {
  if (fooSchema.validate()) {
    // passed
  }
};

const barSubmit = () => {
  if (barSchema.validate()) {
    // passed
  }
};
</script>

Combinations

vue
<script lang="ts" setup>
const fooSchema = useSchema(
  /* ... */
  toRef(state, 'fooForm'),
  toRef(state, 'fooValdn'),
);

const barSchema = useSchema(
  /* ... */
  toRef(state, 'barForm'),
  toRef(state, 'barValdn'),
);

const submit = () => {
  if ([fooSchema, barSchema].map((schema) => schema.validate()).every(Boolean)) {
    // passed
  }
};
</script>

Released under the MIT License.