Documentation
¶
Overview ¶
Package jsonform provides JSON Schema HTML form renderer.
Index ¶
- type Form
- type FormItem
- type FormSchema
- type Page
- type Repository
- func (r *Repository) Add(values ...any) error
- func (r *Repository) AddNamed(value any, name string) error
- func (r *Repository) GetSchema() usecase.Interactor
- func (r *Repository) Mount(s *web.Service, prefix string)
- func (r *Repository) Name(value any) string
- func (r *Repository) Names() []string
- func (r *Repository) Render(w io.Writer, p Page, forms ...Form) error
- func (r *Repository) Schema(value any) *FormSchema
- func (r *Repository) SchemaByName(name string) *FormSchema
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Form ¶ added in v0.2.0
type Form struct {
// Name is used in form elements identifiers, form number is used for empty name.
Name string `json:"name,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
SchemaName string `json:"schemaName,omitempty"`
ValueURL string `json:"valueUrl,omitempty"`
SubmitURL string `json:"submitUrl,omitempty"`
SubmitMethod string `json:"submitMethod,omitempty"`
SuccessStatus int `json:"successStatus,omitempty"`
// OnSuccess is a javascript callback that receives XMLHttpRequest value in case of successful response.
OnSuccess template.JS `json:"-"`
// OnFail is a javascript callback that receives XMLHttpRequest value in case of a failure response.
OnFail template.JS `json:"-"`
// OnError is a javascript callback that receives string HTML value in case of an error while processing the form.
OnError template.JS `json:"-"`
// OnBeforeSubmit is a javascript callback that receives form data after Submit button is clicked and before request is sent.
OnBeforeSubmit template.JS `json:"-"`
// OnRequestFinished is a javascript callback that receives XMLHttpRequest after request is finished.
OnRequestFinished template.JS `json:"-"`
Schema *FormSchema `json:"schema,omitempty"`
Value any `json:"value,omitempty"`
// SubmitText is an optional description of submit button.
SubmitText string `json:"-"`
// BeforeForm is injected before form container.
BeforeForm template.HTML `json:"-"`
// AfterForm is injected after form container.
AfterForm template.HTML `json:"-"`
}
Form describes form parameters.
type FormItem ¶
type FormItem struct {
Key string `json:"key,omitempty" example:"longmood"`
FormType string `` /* 176-byte string literal not displayed */
FormTitle string `json:"title,omitempty" example:"Submit"`
Items []FormItem `json:"items,omitempty"`
ReadOnly bool `json:"readonly,omitempty"`
Prepend string `json:"prepend,omitempty" example:"I feel"`
Append string `json:"append,omitempty" example:"today"`
NoTitle bool `json:"notitle,omitempty"`
HtmlClass string `json:"htmlClass,omitempty" example:"usermood"`
HtmlMetaData map[string]string `json:"htmlMetaData,omitempty" example:"{\"style\":\"border: 1px solid blue\",\"data-title\":\"Mood\"}"`
FieldHtmlClass string `json:"fieldHtmlClass,omitempty" example:"input-xxlarge"`
Placeholder string `json:"placeholder,omitempty" example:"incredibly and admirably great"`
InlineTitle string `json:"inlinetitle,omitempty" example:"Check this box if you are over 18"`
TitleMap map[string]string `json:"titleMap,omitempty" description:"Title mapping for enum."`
ActiveClass string `json:"activeClass,omitempty" example:"btn-success" description:"Button mode for radio buttons."`
HelpValue string `json:"helpvalue,omitempty" example:"<strong>Click me!</strong>"`
Html string `json:"html,omitempty"`
OptionalToggle bool `json:"optionalToggle,omitempty"`
OptionalToggleLabel string `json:"optionalToggleLabel,omitempty"`
AceMode string `json:"aceMode,omitempty" example:"json"`
AceTheme string `json:"aceTheme,omitempty" example:"twilight"`
}
FormItem defines form item rendering parameters.
type FormSchema ¶
type FormSchema struct {
Form []FormItem `json:"form,omitempty"`
Schema jsonschema.Schema `json:"schema"`
}
FormSchema describes form elements.
type Page ¶ added in v0.2.0
type Page struct {
// AppendHTMLHead is injected into the <head> of an HTML document.
AppendHTMLHead template.HTML
// PrependHTML is added before the forms.
PrependHTML template.HTML
// AppendHTML is added after the forms.
AppendHTML template.HTML
// Title is set to HTML document title.
Title string
}
Page allows page customizations.
type Repository ¶
type Repository struct {
// Strict requires all schemas to be added in advance.
Strict bool
// contains filtered or unexported fields
}
Repository manages form schemas and provides integration helpers.
func NewRepository ¶
func NewRepository(reflector *jsonschema.Reflector) *Repository
NewRepository creates schema repository.
func (*Repository) Add ¶ added in v0.2.0
func (r *Repository) Add(values ...any) error
Add adds schemas of value samples. It stops on the first error.
func (*Repository) AddNamed ¶ added in v0.2.0
func (r *Repository) AddNamed(value any, name string) error
AddNamed registers schema with custom name, this is not needed if default name is good enough.
func (*Repository) GetSchema ¶
func (r *Repository) GetSchema() usecase.Interactor
GetSchema returns JSONForm schema.
func (*Repository) Mount ¶
func (r *Repository) Mount(s *web.Service, prefix string)
Mount attaches handlers to web service.
func (*Repository) Name ¶ added in v0.2.0
func (r *Repository) Name(value any) string
Name returns schema name by sample value.
func (*Repository) Names ¶ added in v0.2.0
func (r *Repository) Names() []string
Names returns names of added schemas.
func (*Repository) Schema ¶
func (r *Repository) Schema(value any) *FormSchema
Schema returns previously added schema by its sample value. It returns nil for unknown schema.
func (*Repository) SchemaByName ¶ added in v0.2.0
func (r *Repository) SchemaByName(name string) *FormSchema
SchemaByName return previously added schema by its name. It returns nil for unknown schema.