Skip to content

Multiple Schemas

Single Instance

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

const barSchema = use_LIB_Schema(
  /* ... */
  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 = use_LIB_Schema(
  /* ... */
  toRef(state, 'fooForm'),
  toRef(state, 'fooValdn'), 
);

const barSchema = use_LIB_Schema(
  /* ... */
  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 = use_LIB_Schema(
  /* ... */
  toRef(state, 'fooForm'),
  toRef(state, 'fooValdn'),
);

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

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

Released under the MIT License.