feat: schema field default, min/max, and pattern#211
Merged
Conversation
…ions Schema fields now support three new declarative options that reduce boilerplate in Rhai scripts: - `default_value:` sets initial field values for new notes instead of zero-values - `min:` / `max:` on number fields for range validation without a full validate closure - `pattern:` on text/email fields for regex validation Built-in validation runs before any closure-based validate, and composes with it (both can produce errors). Frontend inputs get HTML min/max/pattern attributes for immediate browser hints, plus IPC-based validation on blur. Closes #122
Update the scripting guide with the three new field definition options: - Field definition table: new keys with examples - Field types table: mention min/max and pattern on relevant types - Section 6 restructured: built-in shortcuts first, then closures
Showcase all three new field options in a real schema:
- price: min 0, max 999999, default 0
- stock: min 0, default 0
- sku: pattern ^[A-Z]{2,4}-\d{3,6}$
- category: changed to select with default "Other"
Script authors can now provide a human-readable error message alongside pattern regex, shown instead of the raw regex when validation fails: pattern_message: "SKU must be 2-4 letters, a dash, then 3-6 digits" Falls back to "Value does not match pattern: ..." when absent.
careck
added a commit
that referenced
this pull request
Jun 9, 2026
PR #211 — default_value, min/max, pattern validation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
default_value:on any field — sets the initial value for new notes instead of zero-values (Rhai key:default_valuesincedefaultis reserved in Rhai)min:/max:on number fields — declarative range validation without writing avalidateclosurepattern:on text/email fields — regex validation shortcutBuilt-in validation runs before closure-based
validate, and both can produce errors. Frontend inputs get HTMLmin/max/patternattributes for immediate browser hints, plus server-side validation on blur via IPC.Closes #122
Changes
FieldDefinitionstruct: 4 new fields (default_value,min_value,max_value,pattern)default_fields(): respects script-specified defaults viadynamic_to_field_value()validate_field()/validate_fields(): run built-in checks (min/max/pattern) before closureFieldDefInfoTauri bridge: carriesminValue,maxValue,pattern,hasDefaultto frontendFieldDefinition: new optional fieldsFieldEditor.tsx: HTMLmin/max/patternattributes on inputsuseNoteForm.ts: triggers blur validation for fields with built-in constraintsRhai script usage
Test plan
cargo test -p krillnotes-core— 699 tests pass (20 new)cargo clippy -p krillnotes-core— cleancargo fmt --check— cleannpx tsc --noEmit— cleanmin/maxnumber field, verify inline error on blurpatterntext field, verify regex validationdefault_value, verify new notes pre-populate