Dynamic data entry form component with JSON schema validation and internationalization support
npm install @browser.style/data-entryA dynamic web component for creating data entry forms with JSON schema validation, internationalization support, and auto-save functionality.
``bash`
npm install @browser.style/data-entry
`javascript`
import '@browser.style/data-entry';
`html
schema="/api/schema"
i18n="/api/i18n"
lang="en">
data="/api/data"
debug
i18n="/api/i18n"
lang="en"
lookup="/api/lookup"
messages="/api/messages"
primary-keys="id,code"
schema="/api/schema"
shadow>
`
- 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
- 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
- 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
`html`
Access form values:
`javascript`
const form = document.querySelector('form');
const entry = form.elements.entry;
console.log(entry.value); // Current form data
`javascript`
const entry = document.querySelector('data-entry');
entry.validateMethod = (schema, data) => {
// Custom validation logic
return {
valid: true,
errors: []
};
};
``json
{
"$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" }
]
}
}
}
}