Features
- 0 dependencies - all shipped code is vanilla JS, minimalistic and performant. The only dependency is optional APM run for logging and debugging purposes.
- 0 css - library is style-agnostic. Specific events can add or remove classes up to your customization.
- Default field values - all fields can have default values set (i.e. country: USA).
- Flexible - any event, validation etc. can be easiely overridden with custom method.
- Internationalization - languages can be added by simply adding
{languageCode}.json
file in data/i18n directory. - Modular and dynamic - specific, required module is loaded dynamically using new ESM feature. Same goes for country and state data.
- Multi-step forms - you can easiely create forms splitted into unlimited number of html pages, which keep passing query parameters until meeting the final page and performing request.
- Real time validation - input is validated instantly when typed. Invalid characters are prevented from inputting (except for copy-pase events, which are unhandled purposedly).
- Recurly v4 - updated from v3 that is soon end of support.
Usage
<script type="module">
import { fcCampaign } from 'https://cdn.jsdelivr.net/npm/@fullcube/campaign@latest/dist/campaign.js';
fcCampaign.bootstrap({
modules: [
{
name: 'add-member'
}
],
actions: [
{
module: 'add-prospect',
name: 'addProspect'
},
{
module: 'discord',
name: 'login'
}
],
api: {
url: `https://api.fullcube.io/api/v1`,
landingPage() {
return {
id: `cjs-landingPage-1`
};
}
},
i18n: {
language: 'en'
},
assets: {
path: `https://cdn.jsdelivr.net/npm/@fullcube/campaign@latest/dist/data`
},
dom: {
disabledClasses: [
`bg-gray-500`,
`-bg-blue-500`,
`-hover:bg-blue-700`
],
errorClasses: [`border-red-500`],
feedbackSuffix: `feedback`,
idPrefix: `fc`
}
});
</script>
How it works?
- Loads dynamically submodule based on configuration (i.e.
add-prospect
). - Loads page configuration from the API.
- Binds to DOM elements with specific id's depending on loaded submodule (i.e.
fc-firstName
, fc-firstName-feedback
; form
, error
and submit
are obligatory). - Listens and reacts to input events.
- On submit performs submodule action defined in configuration. When redirected - persists all existing query parameters along with data from filled form.
Project structure
Showcase
Contains example pages required for development setup.
Modules
Modules are parts of library loaded on demand. They define fields that are should be hijacked from DOM, their validation methods and actions available to perform on form submit via actions
option. Logically, one module should handle single usual use case.
TODO
- Specific build targetting old browsers