Skip to content

Commit

Permalink
tests: minimal demo added
Browse files Browse the repository at this point in the history
  • Loading branch information
jankapunkt committed Dec 19, 2023
1 parent 3fd6b90 commit 5473371
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
16 changes: 16 additions & 0 deletions testapp/client/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<head>
<meta charset="UTF-8">
<title>AutoForm DEMO</title>
</head>
<body>
<div class="container">
<h1>AutoForm DEMO</h1>

{{> quickForm id="userForm" type="normal" schema=schema}}

{{#let userDoc=userDoc}}
<span>Name: {{userDoc.name}}</span>
<span>Age: {{userDoc.age}}</span>
{{/let}}
</div>
</body>
47 changes: 47 additions & 0 deletions testapp/client/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Template } from 'meteor/templating'
import { ReactiveVar } from 'meteor/reactive-var'
import SimpleSchema from 'simpl-schema'
import { Tracker } from 'meteor/tracker'
import './setup'
import './main.html'

SimpleSchema.extendOptions(['autoform'])
const schema = new SimpleSchema({
name: {
type: String,
min: 2,
max: 20
},
age: {
type: Number,
min: 18,
max: 120,
autoform: {
min: 18,
max: 120,
defaultValue: 18,
}
}
}, { tracker: Tracker })

Template.body.onCreated(function () {
const instance = this
instance.user = new ReactiveVar()
})

Template.body.helpers({
schema () {
return schema
},
userDoc () {
return Template.instance().user.get()
}
})

Template.body.events({
'submit #userForm' (event, instance) {
event.preventDefault()
const { insertDoc } = AutoForm.getFormValues('userForm')
instance.user.set(insertDoc)
}
})
9 changes: 9 additions & 0 deletions testapp/client/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.css' // optional, default theme
import popper from '@popperjs/core'
import { AutoFormThemeBootstrap5 } from 'meteor/communitypackages:autoform-bootstrap5/static'
import 'meteor/aldeed:autoform/static'

AutoForm.load()
AutoFormThemeBootstrap5.load()
AutoForm.setDefaultTemplate('bootstrap5')

0 comments on commit 5473371

Please sign in to comment.