### Manual Installation
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Clone the repository and include the local files.
```bash
git clone https://github.com/hollodk/beast-validator.git
```
```html
```
--------------------------------
### Install via NPM
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Install the package and import it into your project.
```bash
npm install beastvalidator
```
```js
import BeastValidator from 'beastvalidator';
```
--------------------------------
### Install via CDN
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Include the library files directly in your HTML document.
```html
```
--------------------------------
### Initialize BeastValidator
Source: https://github.com/hollodk/beast-validator/blob/main/index.html
Basic setup for a form using the BeastValidator constructor.
```html
```
--------------------------------
### Install via NPM
Source: https://github.com/hollodk/beast-validator/blob/main/index.html
Use this command to add BeastValidator to your Node.js project.
```bash
npm install beastvalidator
```
--------------------------------
### Install via Composer
Source: https://github.com/hollodk/beast-validator/blob/main/index.html
Use this command to add BeastValidator to your PHP project.
```bash
composer require hollodk/beastvalidator
```
--------------------------------
### Initialize Basic Form Validation
Source: https://github.com/hollodk/beast-validator/blob/main/index.html
Basic setup for attaching BeastValidator to a form with an onSuccess callback.
```html
```
--------------------------------
### Define Advanced HTML Form
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Example form using various validation attributes like data-match, pattern, and data-min/max.
```html
```
--------------------------------
### Initialize with Advanced Options
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Configure the validator with specific UI and callback settings.
```js
new BeastValidator('myForm', {
tooltips: 'top-center',
autoSubmit: false,
debug: true,
initSteps: false,
onFail: (fields) => console.warn('Invalid fields:', fields),
onSuccess: (data) => alert('Form successful'),
});
```
--------------------------------
### Configure Module Mapping
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Define the package entry points in your package.json for bundler compatibility.
```json
{
"main": "dist/validate.umd.js",
"module": "dist/validate.esm.js",
"unpkg": "dist/validate.min.js",
"jsdelivr": "dist/validate.min.js"
}
```
--------------------------------
### Include via CDN
Source: https://github.com/hollodk/beast-validator/blob/main/index.html
Add these tags to your HTML to load the library and its default styles.
```html
```
--------------------------------
### Control Step Wizard via JavaScript
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Use these methods to programmatically navigate between steps.
```js
validator.nextStep();
validator.prevStep();
```
--------------------------------
### Wizard Navigation Methods
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Methods to control navigation in a multi-step form.
```APIDOC
## validator.nextStep()
### Description
Advances the form to the next step.
## validator.prevStep()
### Description
Returns the form to the previous step.
```
--------------------------------
### Clone the repository
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Use this command to clone the beast-validator repository to your local machine.
```bash
git clone https://github.com/hollodk/beast-validator.git
```
--------------------------------
### Enable Step Navigation
Source: https://github.com/hollodk/beast-validator/blob/main/index.html
Initialize multi-step form validation using the initSteps option and data-step attributes.
```javascript
...
new BeastValidator('#stepForm', {
initSteps: true,
onStepChange: step => console.log('Step:', step)
});
```
--------------------------------
### Using Beast Validator via Script Tag
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Include the minified UMD build directly in HTML files for vanilla sites or CMS environments where no build step is present.
```html
```
--------------------------------
### Define Step Wizard HTML Structure
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Wrap form sections with data-step attributes and use data-next/data-prev buttons to control the flow.
```html
Step 1
Step 2
Step 3 / Thank you
```
--------------------------------
### validator.prevStep()
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Navigates the form wizard to the previous step.
```APIDOC
## validator.prevStep()
### Description
Reverts the multi-step form wizard to the previous step.
### Method
Method call
### Parameters
None
```
--------------------------------
### validator.nextStep()
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Navigates the form wizard to the next step.
```APIDOC
## validator.nextStep()
### Description
Advances the multi-step form wizard to the next defined step.
### Method
Method call
### Parameters
None
```
--------------------------------
### Public API Usage
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Initialize the validator and use methods for form validation, wizard navigation, and resetting.
```js
const validator = new BeastValidator('form');
// Validate the whole form
validator.validate();
// Validate a single field
validator.validateField(document.querySelector('[name="email"]'));
// Control step wizard
validator.nextStep();
validator.prevStep();
// Reset form
validator.reset();
// Extend language support
setMessages(lang, messages)
```
--------------------------------
### Configure Error Summary
Source: https://github.com/hollodk/beast-validator/blob/main/index.html
Render form errors in a specific container by setting the errorSummaryTarget option.
```javascript
const validator = new BeastValidator('#form', {
errorSummaryTarget: '#summary',
});
```
--------------------------------
### Importing Beast Validator in Modern JavaScript Apps
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Use the ESM build for projects utilizing Vite, Webpack, or Rollup to enable tree-shaking and build optimizations.
```js
import BeastValidator from './dist/validate.esm.js';
const validator = new BeastValidator('formId', { ... });
```
--------------------------------
### Override Default Styles
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Apply custom CSS classes to the tooltip and error messages, or define animations like shake.
```css
.beast-tooltip {
background: #f44336;
color: #fff;
padding: 5px 10px;
border-radius: 4px;
}
.beast-error-msg {
color: red;
font-size: 0.85em;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-4px); }
75% { transform: translateX(4px); }
}
.shake { animation: shake 0.3s ease-in-out; }
```
--------------------------------
### BeastValidator Constructor
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Initializes a new instance of the validator for a specific form element.
```APIDOC
## new BeastValidator(formSelector)
### Description
Initializes the validator instance for the specified form.
### Parameters
- **formSelector** (string) - Required - The CSS selector for the form element.
```
--------------------------------
### Debugging Beast Validator in Browser
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Use the non-minified UMD build for easier inspection and debugging within browser developer tools.
```html
```
--------------------------------
### Internationalization Methods
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Methods for managing language-specific error messages.
```APIDOC
## validator.setMessages(lang, messages)
### Description
Defines error messages for a specific language.
## validator.setLanguage(lang)
### Description
Sets the active language for the validator.
```
--------------------------------
### Configure API Submission
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Use the submitTo option to automatically post validated form data to an API endpoint.
```js
new BeastValidator('myForm', {
submitTo: {
url: 'https://api.example.com/form',
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
onResponse(response) {
console.log('[onResponse]', response);
alert('🎉 Submission successful!');
// You can redirect or update the UI here
},
onError(error) {
console.warn('[onError]', error);
alert('❌ Something went wrong. Please try again.');
// You can re-enable a button or show server-side messages
},
},
});
```
--------------------------------
### Define HTML Form for Validation
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Create a standard HTML form with an ID to be targeted by the validator.
```html
```
--------------------------------
### submitTo Configuration
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Configures the validator to automatically submit form data to a specified API endpoint upon successful validation.
```APIDOC
## submitTo Configuration
### Description
Configures automatic submission of validated form data to an external API endpoint.
### Parameters
- **url** (string) - Required - The destination API endpoint URL.
- **method** (string) - Required - The HTTP method (e.g., POST).
- **headers** (object) - Optional - HTTP headers to include in the request.
- **onResponse** (func) - Optional - Callback function executed upon successful API response.
- **onError** (func) - Optional - Callback function executed when the API request fails.
```
--------------------------------
### Enable Debugging in BeastValidator
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Set the debug property to true to enable verbose console logging of lifecycle events.
```js
new BeastValidator('myForm', { debug: true });
```
--------------------------------
### Configure Custom Language Messages
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Set localized error messages and switch the active language for the validator.
```js
validator.setMessages('fr', {
required: 'Ce champ est requis',
email: 'Adresse e-mail invalide'
});
validator.setLanguage('fr');
```
--------------------------------
### Implement Custom Validator
Source: https://github.com/hollodk/beast-validator/blob/main/index.html
Define a custom validation rule using addValidator, supporting asynchronous operations.
```javascript
```
--------------------------------
### Custom Validator Registration
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Allows adding custom validation logic to the validator instance.
```APIDOC
## validator.addValidator(name, callback)
### Description
Registers a custom validation function.
### Parameters
- **name** (string) - Required - The name of the validator used in the data-validator attribute.
- **callback** (function) - Required - An async function that receives the field element and returns true if valid, or an error message string if invalid.
```
--------------------------------
### Form Validation Methods
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Methods to trigger validation for the entire form or specific fields.
```APIDOC
## validator.validate()
### Description
Validates all fields within the form.
## validator.validateField(element)
### Description
Validates a single form field.
### Parameters
- **element** (HTMLElement) - Required - The input element to validate.
```
--------------------------------
### Custom Field Validator Implementation
Source: https://github.com/hollodk/beast-validator/blob/main/README.md
Define a custom validation rule and attach it to an input element using the data-validator attribute.
```html
```
```js
validator.addValidator('checkUsername', async (field) => {
const value = field.value.trim();
if (value === 'admin') return 'Username taken';
return true;
});
```
--------------------------------
### Switch Validation Language
Source: https://github.com/hollodk/beast-validator/blob/main/index.html
Update the validator language dynamically using the setLanguage method.
```javascript
validator.setLanguage('de'); // Change to German
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.