
ZidanForm is a dependency-free JavaScript library for styling and enhancing native form controls, from searchable select dropdowns to file uploads and radio/checkbox inputs.
It preserves native form values and validation, and offers dedicated select-only and file-only builds for pages that do not need the full set of controls.
Features
- Searchable dropdowns, comboboxes, multiple selections, and tag inputs.
- Remote option loading with pagination, caching, and request cancellation.
- Checkboxes, switches, radio groups, and multiple field layouts.
- Drag-and-drop file selection, previews, upload progress, cancellation, and retry.
- Input icons, clear buttons, number steppers, and phone formatting.
- Range sliders, native date/time picker buttons, and date restrictions.
- Native
FormData,form.reset(), and constraint-validation support. - Five theme presets, CSS variables, RTL support, and framework styling adapters.
- Async custom validation and typed ESM entry points.
How To Use It
Choose the right build
| Controls needed | Files in the package |
|---|---|
| Full form | zidan-form.js, plugin-core.css, plugin-theme.css. |
| Select-only | dist/select/zidan-select.js, dist/select/plugin-select-core.css, dist/select/plugin-select-theme.css. |
| File-only | dist/file/zidan-file.js, dist/file/plugin-file-core.css, dist/file/plugin-file-theme.css. |
Basic Usage
Load core CSS before theme CSS. The full browser build initializes marked controls after the DOM is ready.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/plugin-core.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/plugin-theme.css"> <form id="account-form"> <label for="country">Country</label> <select id="country" name="country" required data-zidan-select="combobox" data-zidan-searchable="true"> <option value="">Choose a country</option> <option value="fr">France</option> <option value="jp">Japan</option> <option value="us">United States</option> </select> <label for="updates"> <input id="updates" type="checkbox" name="updates" value="yes" data-zidan="checkbox" data-zidan-variant="switch"> Email updates </label> <fieldset data-zidan="radio-group" data-zidan-variant="inline"> <legend>Account type</legend> <label><input type="radio" name="account" value="personal" checked> Personal</label> <label><input type="radio" name="account" value="business"> Business</label> </fieldset> <label for="avatar">Profile image</label> <input id="avatar" type="file" name="avatar" accept="image/*" data-zidan="file" data-zidan-variant="avatar"> <button type="submit">Save</button> <button type="reset">Reset</button> </form> <script src="https://cdn.jsdelivr.net/npm/[email protected]/zidan-form.js"></script>
Enhance number, phone, and range inputs
The full build also accepts data-zidan="input" on number, telephone, date/time, range, and text controls.
<label for="quantity">Quantity</label>
<input id="quantity" type="number" name="quantity" value="1" min="1" max="10"
data-zidan="input" data-zidan-stepper="split">
<label for="mobile">Phone</label>
<input id="mobile" type="tel" name="mobile" data-zidan="input"
data-zidan-phone="true" data-zidan-phone-country="US"
data-zidan-phone-format="international">
<label for="amount">Amount</label>
<input id="amount" type="range" name="amount" min="0" max="100" value="50"
data-zidan="input" data-zidan-range-variant="stepped"
data-zidan-range-ticks="0,25,50,75,100"
data-zidan-range-tick-labels="true" data-zidan-output="#amount-value">
<output id="amount-value" for="amount"></output>Use a smaller browser bundle
For a page with only a select, use the select-only build. Keep the native <select> and initialize it by selector, ID, or element.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/select/plugin-select-core.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/select/plugin-select-theme.css"> <select id="team" name="team"> <option value="design">Design</option> <option value="engineering">Engineering</option> <option value="support">Support</option> </select> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/select/zidan-select.js"></script> <script> const teamPicker = zidanSelect('#team', { mode: 'combobox', searchable: true, clearable: true }); </script>
For file inputs only, replace these three files with dist/file/plugin-file-core.css, dist/file/plugin-file-theme.css, and dist/file/zidan-file.js. Initialize a file input with zidanField().
Install with npm
npm install zidan-select
import ZidanForm, { initZidanForms, initZidanSelects, zidanField } from 'zidan-select';
import 'zidan-select/css/core';
import 'zidan-select/css/theme';
initZidanSelects(document);
initZidanForms(document);For a smaller module, import from zidan-select/select or zidan-select/file and use the corresponding /css/core and /css/theme exports.
Initialize existing controls with JavaScript
Use zidanSelect() for a plain select that has no Zidan attributes. The function accepts a selector, element, or NodeList.
<select id="products" name="product"> <option value="sku-42">Keyboard</option> <option value="sku-43">Mouse</option> </select>
const picker = zidanSelect('#products', {
mode: 'combobox',
label: 'Product',
placeholder: 'Search products',
searchable: true,
clearable: true
});
picker.getValue();
picker.setValue('sku-42');
picker.setOptions([
{ value: 'sku-42', label: 'Keyboard' },
{ value: 'sku-43', label: 'Mouse', group: 'Accessories' }
]);Configure controls in HTML
Add data-zidan-options as JSON or use zidan-select, zidan-field, and zidan-form marker classes. For automatic selector targeting, assign window.ZIDAN_FORM_CONFIG before loading the library.
data-zidan-options accepts JSON values. Define callbacks, custom upload handlers, and SVG markup in JavaScript. An explicit target option takes precedence over JSON options, followed by individual data attributes and defaults.
<select class="zidan-select" name="skills" multiple
data-zidan-options='{"mode":"tags","maxTags":3,"placeholder":"Add skills"}'>
<option value="css">CSS</option>
<option value="js">JavaScript</option>
</select>
<script>
window.ZIDAN_FORM_CONFIG = {
targets: ['#department'],
fieldTargets: [{ selector: '#photo', options: { variant: 'gallery' } }],
formTargets: ['#registration']
};
</script>
<script src="https://cdn.jsdelivr.net/npm/zidan-select/zidan-form.js"></script>Load select options from an API
The remote endpoint must return items you can map to { value, label }. Supply fetchPageSize and return { items, hasMore } for paginated results. The callback receives an AbortSignal and paging context.
For a declarative endpoint, set data-zidan-fetch-url plus optional query, page-size, item-path, and total-path attributes on the native select.
<select id="customer" name="customer"></select>
const customers = zidanSelect('#customer', {
mode: 'combobox',
fetchPageSize: 20,
fetchOptions: async (query, signal, { page, pageSize }) => {
const params = new URLSearchParams({
q: query,
page: String(page),
limit: String(pageSize)
});
const response = await fetch('/api/customers?' + params, { signal });
if (!response.ok) throw new Error('Unable to load customers');
const data = await response.json();
return {
items: data.items.map(item => ({ value: item.id, label: item.name })),
hasMore: data.hasMore
};
}
});Add upload progress to a file input
Set uploadUrl to a server endpoint that accepts multipart POST requests. ZidanForm handles the picker, progress UI, cancellation, and retry; the server must process and store uploaded files.
simulateUpload: true previews the upload UI locally and sends no files to the server. To use your own transport, supply upload(file, context) and report progress through context.onProgress(); finish with a resolved Promise or context.complete().
<input type="file" id="attachments" name="attachments" multiple>
const uploads = zidanField('#attachments', {
variant: 'dropzone',
accept: 'image/*,.pdf',
maxFiles: 4,
maxSizeMB: 5,
uploadUrl: '/api/uploads',
onUploadProgress: ({ name, progress }) => {
console.log(name, progress);
}
});
uploads.getUploadState();Validate a field asynchronously
An async validator receives { signal, field, instance } as its third argument. A pending check sets the native validity state until it finishes; the previous request is aborted if the input changes.
<input type="email" id="email" name="email" required>
const emailField = zidanField('#email', {
alwaysValidate: true,
showValidState: true,
validate: async (value, field, { signal }) => {
if (!value) return true;
const response = await fetch(
'/api/check-email?value=' + encodeURIComponent(value),
{ signal }
);
if (!response.ok) throw new Error('Validation is unavailable');
const result = await response.json();
return result.taken ? 'Email address is already in use.' : true;
}
});
emailField.validate().then((valid) => console.log(valid));Configuration Reference
Field options work with checkbox, radio, file, text, and other native inputs. Select options apply to ZidanSelect instances. Values that depend on the native input use the corresponding native attribute as their default.
Shared field options
| Option / API | Description |
|---|---|
variant | Control skin. Default default for checkboxes; file and radio groups have their own variants. Attribute: data-zidan-variant. |
layout | Field layout, default stacked: stacked, inline, compact, floating, outlined, card. data-zidan-layout. |
theme | Theme preset, default default: default, modern, minimal, dark, glass. data-zidan-theme/data-zs-theme. |
framework | CSS framework adapter, default none: none, bootstrap, tailwind, bulma, foundation, vanilla. data-zidan-framework/data-zs-framework. |
label / hint | Label and help text. data-zidan-label, data-zidan-hint. |
description / descriptions | Secondary text for card-style choices; descriptions maps radio values to text. data-zidan-description. |
messages | Override validation messages by rule name. |
validate(value, field, context) | Custom validation; return true, false, an error message, Error, or a Promise. Context has signal, field, and instance. |
showValidState | Display positive async validation feedback; default false. |
validation | Initial valid or invalid state. data-zidan-validation. |
alwaysValidate | Show invalid state on native failure before blur; default false. |
indeterminate | Initial mixed checkbox state; default false. data-zidan-indeterminate. |
clearable | Clear control for text/search fields; auto-enabled for search inputs. data-zidan-clear. |
reveal | Password visibility toggle; default false. data-zidan-reveal. |
prefix / suffix | Text affixes displayed beside an input. data-zidan-prefix, data-zidan-suffix. |
counter | Character limit display; defaults to native maxlength. data-zidan-counter. |
rows | Textarea row count; also available as the native rows attribute. |
output | Target selector for the mirrored range value. data-zidan-output. |
title / dropHint | File picker title and hint; default title Choose a file. data-zidan-title, data-zidan-drop-hint. |
accept | Allowed file types, read from native accept. |
maxFiles | Maximum selected files. data-zidan-max-files. |
maxSize / maxSizeMB | Size per file in bytes or MB; maxSize takes precedence. data-zidan-max-size, data-zidan-max-size-mb. |
labels | Maps radio values to label fallback strings. |
clearLabel | Clear button text; Clear all or Clear field by control. |
showPasswordLabel / hidePasswordLabel | Password toggle labels; defaults Show / Hide. |
Checkbox, switch, and radio options
| Option / API | Description |
|---|---|
variant | Checkbox: default, switch, card, button, minimal. Radio: stacked, inline, card, button, tile. |
switchStyle | Switch skin: ios, material, square, labeled, icon. data-zidan-switch-style. |
onLabel / offLabel | Labels for checked and unchecked switch states. data-zidan-on-label, data-zidan-off-label. |
deselectable | Permit clearing the currently selected radio by clicking it again. data-zidan-deselectable. |
Text, number, and phone options
| Option / API | Description |
|---|---|
autoIcon | Use the icon assigned to the input type; default false. data-zidan-auto-icon. |
icon | Registered icon name, SVG markup, or auto. data-zidan-icon. |
iconPosition | left (default) or right. data-zidan-icon-position. |
iconClickable | Render a button for the icon; default false. data-zidan-icon-clickable. |
iconLabel | Accessible name for a clickable icon. data-zidan-icon-label. |
validationIcon | Display state icons; default false. data-zidan-validation-icon. |
stepper | Number stepper, default false; accepts true or stacked, split, inline. data-zidan-stepper. |
stepperPosition | left or right (default) for inline steppers. data-zidan-stepper-position. |
stepperWrap | Wrap from the maximum to the minimum and vice versa; default false. data-zidan-stepper-wrap. |
stepperLongPress | Hold to repeat; default true. data-zidan-stepper-long-press. |
stepperDelay / stepperInterval | Initial repeat delay 420 ms and repeat interval 90 ms. data-zidan-stepper-delay, data-zidan-stepper-interval. |
stepperUpLabel / stepperDownLabel | Button labels, default Increase value / Decrease value. |
stepperStep | Step override; defaults to native step. |
phone | Phone formatting, default off. Accepts true or an object containing country, format, showCountry, countries, and validate. data-zidan-phone. |
phoneCountry | ISO two-letter country code; default US. data-zidan-phone-country. |
phoneFormat | national, international, or e164. data-zidan-phone-format. |
phoneCountrySelect | Show a country selector; default true. data-zidan-phone-country-select. |
phoneCountries | Enabled country list. data-zidan-phone-countries. |
phoneCountryLabel | Selector accessible name, default Country code. |
phone.validate | Enable phone-number validation; default true. |
Range, date, and time options
| Option / API | Description |
|---|---|
rangeVariant | default, gradient, stepped, minimal. data-zidan-range-variant. |
rangeBubble | Show a value bubble; default true. data-zidan-range-bubble. |
rangeBubbleMode | Bubble visibility: always (default), active, or never. data-zidan-range-bubble-mode. |
rangeBubblePosition | top (default) or bottom. data-zidan-range-bubble-position. |
rangeFill | Show the selected track fill; default true. data-zidan-range-fill. |
rangeMinMax | Show range endpoints; default true. data-zidan-range-minmax. |
rangeMinLabel / rangeMaxLabel | Custom labels for the ends of the scale. data-zidan-range-min-label, data-zidan-range-max-label. |
rangeTicks | Tick count, array, or accepted delimited string; default 0. data-zidan-range-ticks. |
rangeTickLabels | Show tick values; default false. data-zidan-range-tick-labels. |
rangeLabels | Object with custom tick labels. |
rangeFormat | String format or formatting function. data-zidan-range-format. |
output | Selector for the mirrored range value. data-zidan-output. |
pickerButton | Date/time native picker button; default false. data-zidan-picker-button. |
pickerIcon | Picker icon name; depends on input type. data-zidan-picker-icon. |
pickerLabel | Picker button accessible name; defaults to Open <type> picker. |
disableWeekends | Block Saturday/Sunday; default false. data-zidan-disable-weekends. |
disabledDates | Date list or predicate function. data-zidan-disabled-dates. |
validateDate(value, date, field, context) | Date validation callback; may return a boolean, message, or Promise. Context includes signal. |
File upload options
| Option / API | Description |
|---|---|
fileVariant / variant | Upload layout: dropzone (default), button, avatar, gallery, compact. data-zidan-file-variant or data-zidan-variant. |
uploadIcon | Upload-area icon; default upload. data-zidan-upload-icon. |
upload / uploadHandler | Custom upload function (file, context). Return a Promise/result or complete via context helpers. |
uploadUrl | Multipart POST endpoint. data-zidan-upload-url. |
uploadField | Multipart file field name; default file. data-zidan-upload-field. |
uploadData | Additional multipart fields; object or (file, field) => object. |
withCredentials | XHR credential flag; default false. data-zidan-with-credentials. |
uploadHeaders / headers | Request headers object or callback. |
simulateUpload | Local progress simulation; default false. data-zidan-simulate-upload. |
simulateDuration | Simulation duration, default 900 ms. data-zidan-simulate-duration. |
autoUpload | Upload immediately after selection; default true. data-zidan-auto-upload. |
showFileMeta | Display file rows; default true. data-zidan-show-file-meta. |
showPreview / preview / previews | Image preview settings; default true. data-zidan-preview. |
replaceTitle | Avatar replacement label; default Change image. |
progressTemplate | Progress label, default Uploading {percent}%. |
uploadedLabel | Completed upload label; default Uploaded. |
failedLabel | Failed upload label; default Upload failed. |
canceledLabel | Canceled upload label; default Upload canceled. |
cancelLabel / retryLabel | Action labels; default Cancel / Retry. |
renderFile | Per-file renderer (itemElement, { file, index, state, field }). |
Select and combobox options
| Option / API | Description |
|---|---|
mode | select (default), combobox, or tags. data-zidan-select/data-zidan-mode. |
layout | Select layout; default classic-clean. data-zidan-layout. |
themeFramework | Framework skin: auto, none, vanilla, bootstrap, tailwind, bulma, foundation; default auto. data-zidan-framework. |
theme | Theme preset; default default. data-zidan-theme. |
id | Generated wrapper root ID prefix. |
name | Name for mount-mode hidden input; defaults to native name. data-zidan-name. |
disabled / required | Initial states; mirror native attributes. data-zidan-disabled for disabled. |
validation | null (default), valid, or invalid. data-zidan-validation. |
scrollbar | default (default), thin, fancy, hover, hidden. data-zidan-scrollbar. |
customClasses | Class map for root, control, input; default empty map. |
options | Array of strings or { value, label, disabled?, group? }. |
suggestions | Suggested tag values. |
value | Initial value or array for multiple/tags. |
label / ariaLabel | Visible/floating and accessible label; ariaLabel defaults to label. data-zidan-label. |
placeholder | Placeholder text. data-zidan-placeholder. |
multiple | Multi-select mode; reflects native multiple. data-zidan-multiple. |
searchable | Search input; defaults to false for plain select mode, otherwise true. data-zidan-searchable. |
clearable | Clear button; default false. data-zidan-clearable. |
closeOnSelect | Close the list after selection, default true for single selection. |
maxDropdownHeight | List height limit, default 280 pixels. |
noResultsText | Empty filtered-results text, default No results found. |
emptyText | No-source-options text, default No options. |
loadingText | Remote loading status, default Searching…. |
clearText | Clear button label, default Clear selection. |
Remote select options
| Option / API | Description |
|---|---|
fetchOptions(query, signal, context) | Async data callback; return items or { items, hasMore }/{ items, total }. Context includes page, pageSize, append, instance. |
fetchPageSize | Pagination size; default 0 (single request). data-zidan-fetch-page-size. |
fetchUrl | Auto-fetch endpoint; default null. data-zidan-fetch-url. |
fetchQueryParam | Query parameter; default q. data-zidan-fetch-query-param. |
fetchPageParam | Page parameter; default page. data-zidan-fetch-page-param. |
fetchSkipParam | Offset parameter alternative; default null. data-zidan-fetch-skip-param. |
fetchPageSizeParam | Limit parameter; default limit. data-zidan-fetch-page-size-param. |
fetchItemsPath | Response item-list dot path; default null. data-zidan-fetch-items-path. |
fetchTotalPath | Total-count path; default null. data-zidan-fetch-total-path. |
fetchHasMorePath | More-results boolean path; default null. data-zidan-fetch-has-more-path. |
fetchMethod | HTTP method, default GET. data-zidan-fetch-method. |
fetchHeaders | HTTP request headers; default null. |
fetchCredentials | Fetch credentials, default same-origin. |
autoLoadMore | Load next page near the list bottom; default true. |
loadMoreText | Footer text; default Load more. |
cacheResults | Cache query/page results; default true. |
debounce | Request delay, default 250 ms. |
minChars | Minimum search length before fetch; default 0. |
searchValues | Search option values and labels; default true. |
Tag and rendering options
| Option / API | Description |
|---|---|
maxTags | Maximum tag count; default Infinity. data-zidan-max-tags. |
minTagLength | Minimum characters per tag; default 1. data-zidan-min-tag-length. |
maxTagLength | Maximum characters per tag; default Infinity. data-zidan-max-tag-length. |
caseSensitive | Case-sensitive duplicate handling; default false. data-zidan-case-sensitive. |
allowFreeText | Accept tags outside options/suggestions; default true. data-zidan-allow-free-text. |
delimiters | Tag delimiters; default [',']. |
commitOnTab / commitOnBlur | Add current text as a tag on Tab/blur; default false. |
valueDelimiter | Value serialization delimiter; default comma. |
filterOption(item, query) | Custom option filter; returns boolean. |
renderOption(item, context) | Custom listbox item HTML or element. |
renderSelected(item, context) | Custom selected item HTML or element. |
renderTag(item, context) | Custom tag HTML or element. |
validateTag(tag, tags, context) | Return true or an error string. |
formatTag(tag, context) | Return formatted tag display string. |
Automatic initialization options
| Option / API | Description |
|---|---|
window.ZIDAN_FORM_CONFIG | Global configuration before script loading; ZIDAN_SELECT_CONFIG is an alias. |
autoInit | Set false to disable automatic scanning. data-zidan-auto-init="false" on <html> also works. |
targets / selectors | Select elements by ID, class, selector string, or { selector, options }. |
fieldTargets | Target supported input/textarea elements, with optional per-target settings. |
formTargets | Additional scopes in which selects and file inputs are initialized. |
options | Shared select settings for the scan. |
fieldOptions / fields | Shared field options; fields is the legacy alias. |
selector | Legacy single select selector; skips the generic attribute scan. |
data-zidan-options | JSON options on any supported marked element. |
marker classes | zidan-select (select), zidan-field (field), zidan-form (scope). |
data-zidan-form | Attribute marking a scope that scans native selects and file inputs. |
JavaScript API
Global functions and managers
| Option / API | Description |
|---|---|
zidanSelect(target, options?) | Initialize one or more select elements; returns one instance or an array. |
initZidanSelects(scope?, options?) | Initialize marked selects in a scope; returns ZidanSelect[]. |
initZidanForms(scope?, options?) | Initialize marked fields in a scope; returns a field array. |
zidanField(target, options?) | Initialize supported field(s), including unmarked inputs; returns an instance, null when unmatched, or an array for multiple targets. |
ZidanForm.init(scope, options) | Initialize supported fields in a scope. |
ZidanForm.field(target, options) | Initialize targeted field(s). |
ZidanForm.get(input) | Retrieve a field instance or null. |
ZidanForm.refresh(scope?) | Scan for new fields and synchronize existing fields. |
ZidanForm.observe(scope, options?) | Observe DOM changes; returns MutationObserver or null. |
ZidanForm.destroyAll() | Destroy all enhanced fields. |
ZidanForm.registerIcon(name, svg) | Register icon SVG markup for input adornments. |
registerIcon(name, svg) / registerZidanIcon(name, svg) | Named exports/browser registration helpers for custom icons. |
formatPhone(value, country?, format?) | Phone formatting helper exported by the module. |
detectPhoneCountry(value) | Detect a phone country from input text where supported. |
ZidanForm.themes / fieldLayouts / frameworks | Available names; themes and fieldLayouts support custom name registration. |
ZidanForm.variants / stepperModes / phoneFormats / phoneCountries | Public accepted variants, modes, formats, and phone-country registry. |
ZidanForm.icons / messages | Built-in icon and validation-message registries. |
ZidanSelect.get(input) | Retrieve a select instance. |
ZidanSelect.destroyAll() | Destroy all select instances. |
ZidanSelect.instances / layouts / frameworks / scrollbars | Select instance registry and accepted layout, framework, scrollbar names. |
ZidanSelect.cacheLimit | Maximum cached remote pages; default 50. |
Select instance methods
| Option / API | Description |
|---|---|
open() / close() / toggle() / isOpen() | Control the listbox visibility or read whether it is open. |
getValue() / setValue(value) | Read or change the selected value; arrays for multiple/tag modes. |
clear() | Clear selected value(s). |
setOptions(items) | Replace options in both the display and native <option> list. |
addTag(value) / removeTag(value) / getTags() | Add, delete, or read tags in tags mode. |
enable() / disable() | Toggle available input state. |
setLayout(name) / setFramework(name) / setScrollbar(name) | Change select appearance settings. |
setValidation(state) | Set valid/invalid state or clear it with null. |
refresh() | Re-read current native select state. |
loadMore() / hasMoreResults() | Load next remote page / read whether one remains. |
getAsyncState() | Read remote loading and pagination state. |
refreshOptions() / clearCache() | Reload remote choices / purge cached pages. |
on(event, handler) / off(event, handler) | Register or remove instance event handlers. |
announce(message) | Announce a status through the select live region. |
destroy() | Remove generated UI, restore the native control, and release listeners. |
Field instance methods
| Option / API | Description |
|---|---|
getValue() / setValue(value) | Read/update native input, checked, radio, or file state. |
update() / refresh() | Re-read native state and update the enhanced field. |
validationTargets() | Native elements used for mirrored constraints. |
setValidation(state) / getValidation() | Set/read valid, invalid, or cleared state. |
setError(message) / clearError() | Set or clear visible error feedback. |
checkAsync() | Run pending custom validation; returns a Promise. |
validate() / isPending() | Run native and custom rules / read pending state. |
setTheme(name) / setFramework(name) / setLayout(name) | Change one field’s styling. |
setIndeterminate(value) / setChecked(value) / isChecked() | Checkbox state helpers. |
stepUp(times?) / stepDown(times?) / setStepper(enabled) | Number step controls. |
getPhoneCountry() / setPhoneCountry(iso) / setPhoneFormat(format) / formatPhone(value?) | Phone-country and formatting helpers. |
openPicker() / showPicker() | Open the native date/time picker when available. |
getFiles() / getUploadState() | Read file list and upload results/status. |
addFiles(files) / replaceFiles(files) / removeFile(nameOrIndex) / clear() | Modify selected files. |
setVariant(name) / setUploader(functionOrUrl) | Change file layout or upload handler. |
uploadAll() / uploadFile(file) / cancelUpload(file) / cancelAll() / retryUpload(file) | Upload lifecycle controls. |
destroy() | Restore the original input and release listeners and any ongoing async work. |
Callbacks
Callbacks are configured in JavaScript options. Every callback receives an object with the instance and the relevant value, item, file, or lifecycle fields.
| Option / API | Description |
|---|---|
onInit | Select: { instance, mode, value }; field: { instance, variant?, type? }. |
onChange | Select: value and previousValue; field: value, checked, or files. |
onInput | Field input and range value. |
onValidation | { instance, state, message? }. |
onSelect | Selected value and item. |
onOpen / onClose | Select visibility changes; receives instance. |
onTagAdd / onTagRemove | Tag and selected value. |
onLoadMore | Page and query when remote pagination begins. |
onError | Error message and error/callback details. |
onIconClick | Icon name and position. |
onStep | Number value and step direction. |
onPicker | Date/time input type. |
onPhoneCountry / onPhoneFormat | Country selection and phone format. |
onRemove | Removed file and index. |
onUploadStart / onUploadProgress / onUploadSuccess | File, name, and size/progress/result information. |
onUpload | Alias for onUploadSuccess. |
onUploadError / onUploadCancel | File, name, and error information where available. |
DOM events
Custom events bubble from the generated field wrapper. Read their payload from event.detail. Native change events also work on the original inputs.
document.addEventListener('zidan:change', (event) => {
console.log(event.detail.value);
});
document.addEventListener('zidan:upload-progress', (event) => {
console.log(event.detail.name, event.detail.progress);
});| Option / API | Description |
|---|---|
zidan:init / zidan:destroy | Instance lifecycle. |
zidan:change / zidan:input | Changed value, checked state, files, or input text. |
zidan:validation / zidan:async-validation | Validity state, async rule result, and message. |
zidan:open / zidan:close / zidan:select | Select opened/closed or an item was selected. |
zidan:no-results | Select query returned no matches. |
zidan:tag-add / zidan:tag-remove | Tag and value information. |
zidan:load-more | Remote query and next page. |
zidan:reveal | Password reveal visibility. |
zidan:clear / zidan:remove | Cleared control or removed file. |
zidan:step | Number value, direction, and step. |
zidan:phone-country / zidan:phone-format | Updated phone country or format. |
zidan:icon-click / zidan:picker | Icon action or native date/time picker request. |
zidan:upload-start / zidan:upload-progress | File upload started or made progress. |
zidan:upload-success / zidan:upload-error / zidan:upload-cancel | Completed, failed, or canceled upload. |
zidan:error | Plugin error, callback, and instance context. |
Themes and Styling
Choose default, modern, minimal, dark, or glass with data-zs-theme. Set data-zs-framework to bootstrap, tailwind, bulma, or foundation for the corresponding CSS adapter. Values resolve from the control to its ancestors and then <html>.
<form data-zs-theme="dark" data-zs-framework="bootstrap">
<select name="region" data-zidan-select="select" data-zidan-layout="soft-pill">
<option value="west">West</option>
<option value="east">East</option>
</select>
</form>Customize a preset by overriding the published --zs-* tokens after the theme stylesheet.
.signup-form {
--zs-primary: #d93854;
--zs-primary-soft: #fff2f4;
--zs-radius: 12px;
--zs-focus-ring: rgba(217, 56, 84, 0.2);
}Public layout and styling hooks
| Option / API | Description |
|---|---|
select layouts | classic-clean, floating-label, soft-pill, bordered-brutalist, glass-elevated. |
field layouts | stacked, inline, compact, floating, outlined, card. |
scrollbar variants | default, thin, fancy, hover, hidden. |
zidan-select / zidan-field / zidan-form | Public marker classes for automatic enhancement and scoped initialization. |
zs-form-grid / zs-full | Public wrapper grid and a field-span modifier; grid is not a field layout value. |
zs-native-input | Native control retained inside the generated wrapper. |
zs-field--invalid / zs-field--valid / zs-field--pending | Validation-state hooks; pending also sets aria-busy. |
zs-range-scale--hidden / zs-range--labels-no-scale | Range scale hidden or spacing reserved when tick labels replace endpoints. |
zs-range-tick--start / zs-range-tick--end | Mark endpoint tick labels in range controls. |
zs-range-bubble--start / zs-range-bubble--end | Bubble-edge positioning hooks for range controls. |
data-zs-validation | Reflected validation state on rendered fields. |
ZidanForm.registerIcon(name, markup) | Register an SVG icon for use with icon and uploadIcon. |
CSS custom properties
| Option / API | Description |
|---|---|
--zs-font-family / --zs-font-size / --zs-line-height | Typography: inherit / 0.9375rem / 1.4. |
--zs-label-size / --zs-height | Label size (0.8125rem) / field height (44px). |
--zs-radius / --zs-chip-radius | Field and chip radii: 10px / 8px. |
--zs-border-width / --zs-gap | Border thickness 1px / spacing 6px. |
--zs-padding-x / --zs-padding-y | Horizontal / vertical input padding: 12px / 5px. |
--zs-dropdown-radius / --zs-dropdown-border-width | Dropdown radius 12px / border width 1px. |
--zs-option-radius / --zs-option-padding-x / --zs-option-padding-y | Option radius 8px, padding 12px / 9px. |
--zs-bg / --zs-text / --zs-text-muted / --zs-placeholder | Control backgrounds, foreground text, muted text, placeholders. |
--zs-border-color / --zs-border-color-hover / --zs-border-color-focus | Normal, hover, and focus borders. |
--zs-border-color-invalid / --zs-border-color-valid | Validation border colors. |
--zs-primary / --zs-primary-contrast / --zs-primary-soft | Accent, contrast text, and light accent surfaces. |
--zs-focus-ring / --zs-focus-ring-width | Focus-ring color and width. |
--zs-chip-bg / --zs-chip-text / --zs-chip-border | Selected tag styling. |
--zs-dropdown-bg / --zs-dropdown-border / --zs-dropdown-shadow | Dropdown surfaces and shadow. |
--zs-option-hover-bg / --zs-option-active-bg / --zs-option-active-text | Hover and keyboard-active option colors. |
--zs-option-selected-bg / --zs-option-selected-text / --zs-group-text | Selected option and group label colors. |
--zs-check-size / --zs-check-radius / --zs-check-gap | Checkbox geometry. |
--zs-check-bg / --zs-check-border / --zs-check-mark | Checkbox background, border, and mark. |
--zs-check-checked-bg / --zs-check-checked-border | Checked-checkbox styles. |
--zs-switch-width / --zs-switch-height / --zs-switch-off / --zs-switch-knob | Switch track geometry and colors. |
--zs-switch-width-lg / --zs-switch-height-lg | Larger switch geometry. |
--zs-switch-on-text / --zs-switch-off-text | Switch labels. |
--zs-radio-size / --zs-radio-border / --zs-radio-gap | Radio geometry. |
--zs-file-drop-bg / --zs-file-drop-border | File drop target colors. |
--zs-file-thumb-bg / --zs-file-thumb-text | File thumbnail colors. |
--zs-field-gap | Spacing in a field; default 6px. |
--zs-icon-color / --zs-icon-hover-bg | Icon and icon button styling. |
--zs-stepper-color / --zs-stepper-hover-bg | Number stepper buttons. |
--zs-phone-border | Phone-country selector separator. |
--zs-radius-pill | Rounded button/check/radio skin, default 999px. |
--zs-avatar-size / --zs-avatar-bg / --zs-avatar-border | Avatar file target size/background/border. |
--zs-range-track / --zs-range-fill / --zs-range-gradient | Range slider track and fill. |
--zs-range-thumb-bg / --zs-range-thumb-border | Range slider thumb styles. |
--zs-range-tick / --zs-range-tick-text | Range tick colors. |
--zs-range-bubble-bg / --zs-range-bubble-text | Range bubble styling. |
--zs-range-angle | RTL-aware gradient angle. |
--zs-upload-track / --zs-upload-bar / --zs-upload-success | Upload progress and success colors. |
Lifecycle and Integration
The original inputs remain the source of truth for values, FormData, file lists, validation, and form.reset(). Call refresh() after programmatic native-state changes; observe dynamic subtrees when controls are inserted later.
For React, Vue, or Angular, initialize after mount and destroy the instances before unmount. In Next.js, keep form initialization in a client component after hydration.
const observer = ZidanForm.observe(document.querySelector('#dialog-body'));
// Before removing the observed container:
observer.disconnect();
ZidanForm.destroyAll();Alternatives and Related Resources
- Customizable Select Box & Input Field Enhancement Library – Choices.js
- Dropzone.js: Versatile JavaScript Drag & Drop File Uploader
- Elegant File Input Enhancement Plugin With JavaScript – filepond
- Custom HTML5 Form Validator In Vanilla JavaScript – Just-validate







