Skip to content

Quasar Preset

Enforma includes a built-in preset for Quasar Framework, making it easy to create forms using Quasar components. This integration provides a seamless experience that leverages Quasar's feature-rich UI components while maintaining Enforma's powerful form management capabilities.

Installation

To use the Quasar preset, you need to have Quasar installed in your project:

bash
# If using Vue CLI
vue add quasar

# If using Vite
npm install quasar @quasar/extras

Follow the Quasar setup instructions to configure it in your Vue application.

Basic Usage

Import and use the Quasar preset:

js
// main.js
import { createApp } from 'vue';
import { EnformaPlugin } from '@encolajs/enforma';
import { useQuasarPreset } from '@encolajs/enforma/presets/quasar'
import { Quasar } from 'quasar';
import App from './App.vue';

// Import Quasar CSS
import 'quasar/dist/quasar.css';
// Import icon libraries
import '@quasar/extras/material-icons/material-icons.css';

// Create the app
const app = createApp(App);

// Configure Quasar
app.use(Quasar, {
  plugins: {}, // import Quasar plugins and add here
});

// Configure Enforma
app.use(EnformaPlugin);

// Apply Quasar preset
useQuasarPreset();

app.mount('#app');

Now use Enforma components with Quasar styling:

vue
<template>
  <q-card class="q-pa-md">
    <Enforma :data="formData" :submitHandler="submit">
      <QuasarField name="name" label="Name" />
      <QuasarField name="email" label="Email" />
      <QuasarField 
        name="country" 
        label="Country" 
        inputComponent="select" 
        :inputProps="{ options: countries, 'emit-value': true, 'map-options': true }" 
      />
    </Enforma>
  </q-card>
</template>

<script setup>
import { ref } from 'vue';
import { Enforma } from '@encolajs/enforma';
// creating a custom field component was needed 
// due to how Quasar is rendering labels and hints/messages 
import QuasarField from '@encolajs/enforma/presets/quasar/Field';
import { QBtn, QCard } from 'quasar';

const formData = ref({
  name: '',
  email: '',
  country: ''
});

const countries = [
  { value: 'us', label: 'United States' },
  { value: 'ca', label: 'Canada' },
  { value: 'mx', label: 'Mexico' }
];

function submit(data) {
  console.log('Form submitted:', data);
}
</script>

Form Components

The preset includes the following mapped components:

Field TypeQuasar Component
inputQInput
selectQSelect
toggleQToggle
switchQToggle

The preset also includes styled button components:

ButtonQuasar Component
EnformaSubmitButtonQBtn (type="submit")
EnformaResetButtonQBtn (type="reset")
EnformaRepeatableAddButtonQBtn (icon="add")
EnformaRepeatableRemoveButtonQBtn (icon="delete")
EnformaRepeatableMoveUpButtonQBtn (icon="arrow_upward")
EnformaRepeatableMoveDownButtonQBtn (icon="arrow_downward")

NOTE

This preset takes advantage of Quasar's UI components and styling conventions. If you need to customize it further, you can modify the preset files or create your own custom components based on them.

Released under the MIT License