Installation
Download or Use CDN
To use Trivule in your project, follow these steps:
https://cdn.jsdelivr.net/npm/trivule@latest/dist/index.umd.js- Include the Trivule library in your web page as you would any other JavaScript file.
Installation via npm
- Navigate to your project directory and run the following command:
npm i trivuleOnce installed, you can use Trivule in your project as needed:
- For validating a single form field:
import { TrivuleInput } from 'trivule';
const trInput = new TrivuleInput('selector'); - For validating an entire form:
import { TrivuleForm } from 'trivule';
const trForm = new TrivuleForm('selector'); - For validating all forms in your project, suitable for classic HTML/CSS projects (vanilla), but also supports declarative validation:
import Trivule from 'trivule';
window.Trivule = Trivule;
Trivue.init();Example
Here's an example of validation that doesn't require JavaScript:
<form @form id="myForm">
<div>
<label class="label">Phone</label>
<input type="text" @v:rules="required|phone:FR" name="phone" />
<div @v:feedback="phone"></div>
</div>
<div>
<label class="label">Date</label>
<input
type="date"
@v:rules="required|date|after:now"
name="date"
/>
<div @v:feedback="date"></div>
</div>
<div>
<label class="label">File</label>
<input
type="file"
@v:rules="required|file|maxFileSize:1MB"
name="file"
/>
<div @v:feedback="file"></div>
</div>
<p><button type="submit" @v:submit>Submit</button></p>
</form>
<script src="https://cdn.jsdelivr.net/npm/trivule@latest/dist/index.umd.js"></script>
<script>
window.Trivule = Trivule;
Trivule.init();
</script>