@browser.style/data-entry
v1.0.21
Published
Dynamic data entry form component with JSON schema validation and internationalization support
Maintainers
Readme
DataEntry
A dynamic web component for creating data entry forms with JSON schema validation, internationalization support, and auto-save functionality.
Installation
npm install @browser.style/data-entryUsage
import '@browser.style/data-entry';<!-- Basic usage -->
<data-entry
data="/api/data"
schema="/api/schema"
i18n="/api/i18n"
lang="en">
</data-entry>
<!-- With all features -->
<data-entry
auto-save="30"
data="/api/data"
debug
i18n="/api/i18n"
lang="en"
lookup="/api/lookup"
messages="/api/messages"
primary-keys="id,code"
schema="/api/schema"
shadow>
</data-entry>Attributes
auto-save: Auto-save interval in secondsdata: URL to fetch form datadebug: Enable debug loggingi18n: URL to fetch translationslang: Language code (default: 'en')lookup: URL to fetch lookup datamessages: URL to fetch validation messagesprimary-keys: Comma-separated primary key fieldsschema: URL to fetch JSON schemashadow: Use shadow DOM
Properties
data: Get/set form data objectschema: Get/set JSON schema objectlookup: Get/set lookup data arrayi18n: Get/set translations objectconstants: Get/set constants objectvalidateMethod: Set custom validation function
Events
de:custom: Custom button clickedde:entry: Form data processedde:notify: Notification triggeredde:resetfields: Fields resetde:submit: Form submittedde:record-created: New record createdde:record-deleted: Record deletedde:record-upserted: Record updated
Form Integration
<form>
<data-entry name="entry"></data-entry>
</form>Access form values:
const form = document.querySelector('form');
const entry = form.elements.entry;
console.log(entry.value); // Current form dataCustom Validation
const entry = document.querySelector('data-entry');
entry.validateMethod = (schema, data) => {
// Custom validation logic
return {
valid: true,
errors: []
};
};Schema Example
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Name",
"render": {
"method": "input",
"attributes": [
{ "type": "text" },
{ "required": "required" }
]
}
}
}
}