Documentation
¶
Overview ¶
Copyright 2016 Wenhui Shen <www.webx.top> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This package provides form creation and rendering functionalities, as well as FieldSet definition. Two kind of forms can be created: base forms and Bootstrap3 compatible forms; even though the latters are automatically provided the required classes to make them render correctly in a Bootstrap environment, every form can be given custom parameters such as classes, id, generic parameters (in key-value form) and stylesheet options.
Copyright 2016 Wenhui Shen <www.webx.top> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func Html5Validate(valid string, f fields.FieldInterface)
- func ValidationEngine(valid string, f fields.FieldInterface)
- type FieldSetType
- func (f *FieldSetType) AddClass(class string) *FieldSetType
- func (f *FieldSetType) AddTag(tag string) *FieldSetType
- func (f *FieldSetType) Data() map[string]interface{}
- func (f *FieldSetType) Disable() *FieldSetType
- func (f *FieldSetType) Elements(elems ...FormElement) *FieldSetType
- func (f *FieldSetType) Enable() *FieldSetType
- func (f *FieldSetType) Field(name string) fields.FieldInterface
- func (f *FieldSetType) Name() string
- func (f *FieldSetType) RemoveClass(class string) *FieldSetType
- func (f *FieldSetType) RemoveTag(tag string) *FieldSetType
- func (f *FieldSetType) Render() template.HTML
- func (f *FieldSetType) SetData(key string, value interface{})
- func (f *FieldSetType) SetTmpl(tmpl string) *FieldSetType
- func (f *FieldSetType) Sort(sortList ...string) *FieldSetType
- func (f *FieldSetType) Sort2Last(fieldsName ...string) *FieldSetType
- func (f *FieldSetType) SortAll(sortList ...string) *FieldSetType
- func (f *FieldSetType) String() string
- type Form
- func (f *Form) AddClass(class string) *Form
- func (f *Form) AddCss(key, value string) *Form
- func (f *Form) Data() map[string]interface{}
- func (f *Form) DeleteParam(key string) *Form
- func (f *Form) Elements(elems ...FormElement) *Form
- func (f *Form) Field(name string) fields.FieldInterface
- func (f *Form) FieldSet(name string) *FieldSetType
- func (f *Form) Fields() []FormElement
- func (f *Form) GenChoices(lenType interface{}, fnType interface{}) interface{}
- func (f *Form) GenChoicesForField(name string, lenType interface{}, fnType interface{}) *Form
- func (f *Form) Html(value interface{}) template.HTML
- func (f *Form) NewFieldSet(name string, elems ...fields.FieldInterface) *FieldSetType
- func (f *Form) RemoveClass(class string) *Form
- func (f *Form) RemoveCss(key string) *Form
- func (f *Form) RemoveElement(name string) *Form
- func (f *Form) Render() template.HTML
- func (f *Form) SetData(key string, value interface{})
- func (f *Form) SetId(id string) *Form
- func (f *Form) SetModel(m interface{}) *Form
- func (f *Form) SetParam(key, value string) *Form
- func (f *Form) Sort(sortList ...string) *Form
- func (f *Form) Sort2Last(fieldsName ...string) *Form
- func (f *Form) SortAll(sortList ...string) *Form
- func (f *Form) String() string
- func (f *Form) Valid(args ...string) (valid *validation.Validation, passed bool)
- type FormElement
Constants ¶
const ( POST = "POST" GET = "GET" )
Form methods: POST or GET.
Variables ¶
var ValidTagFn func(string, fields.FieldInterface) = Html5Validate
Functions ¶
func Html5Validate ¶
func Html5Validate(valid string, f fields.FieldInterface)
func ValidationEngine ¶
func ValidationEngine(valid string, f fields.FieldInterface)
Types ¶
type FieldSetType ¶
type FieldSetType struct { AppendData map[string]interface{} // contains filtered or unexported fields }
FieldSetType is a collection of fields grouped within a form.
func FieldSet ¶
func FieldSet(name string, elems ...fields.FieldInterface) *FieldSetType
FieldSet creates and returns a new FieldSetType with the given name and list of fields. Every method for FieldSetType objects returns the object itself, so that call can be chained.
func (*FieldSetType) AddClass ¶
func (f *FieldSetType) AddClass(class string) *FieldSetType
AddClass saves the provided class for the fieldset.
func (*FieldSetType) AddTag ¶
func (f *FieldSetType) AddTag(tag string) *FieldSetType
AddTag adds a no-value parameter (e.g.: "disabled", "checked") to the fieldset.
func (*FieldSetType) Data ¶
func (f *FieldSetType) Data() map[string]interface{}
func (*FieldSetType) Disable ¶
func (f *FieldSetType) Disable() *FieldSetType
Disable adds tag "disabled" to the fieldset, making it unresponsive in some environment (e.g.: Bootstrap).
func (*FieldSetType) Elements ¶
func (f *FieldSetType) Elements(elems ...FormElement) *FieldSetType
Elements adds the provided elements to the fieldset.
func (*FieldSetType) Enable ¶
func (f *FieldSetType) Enable() *FieldSetType
Enable removes tag "disabled" from the fieldset, making it responsive.
func (*FieldSetType) Field ¶
func (f *FieldSetType) Field(name string) fields.FieldInterface
Field returns the field identified by name. It returns an empty field if it is missing.
func (*FieldSetType) Name ¶
func (f *FieldSetType) Name() string
Name returns the name of the fieldset.
func (*FieldSetType) RemoveClass ¶
func (f *FieldSetType) RemoveClass(class string) *FieldSetType
RemoveClass removes the provided class from the fieldset, if it was present. Nothing is done if it was not originally present.
func (*FieldSetType) RemoveTag ¶
func (f *FieldSetType) RemoveTag(tag string) *FieldSetType
RemoveTag removes a tag from the fieldset, if it was present.
func (*FieldSetType) Render ¶
func (f *FieldSetType) Render() template.HTML
Render translates a FieldSetType into HTML code and returns it as a template.HTML object.
func (*FieldSetType) SetData ¶
func (f *FieldSetType) SetData(key string, value interface{})
func (*FieldSetType) SetTmpl ¶
func (f *FieldSetType) SetTmpl(tmpl string) *FieldSetType
func (*FieldSetType) Sort ¶
func (f *FieldSetType) Sort(sortList ...string) *FieldSetType
Sort("field1:1,field2:2") or Sort("field1:1","field2:2")
func (*FieldSetType) Sort2Last ¶
func (f *FieldSetType) Sort2Last(fieldsName ...string) *FieldSetType
func (*FieldSetType) SortAll ¶
func (f *FieldSetType) SortAll(sortList ...string) *FieldSetType
SortAll("field1,field2") or SortAll("field1","field2")
func (*FieldSetType) String ¶
func (f *FieldSetType) String() string
type Form ¶
type Form struct { AppendData map[string]interface{} // contains filtered or unexported fields }
Form structure.
func NewFormFromModel ¶
NewFormFromModel returns a base form inferring fields, data types and contents from the provided instance. A Submit button is automatically added as a last field; the form is editable and fields can be added, modified or removed as needed. Tags can be used to drive automatic creation: change default widgets for each field, skip fields or provide additional parameters. Basic field -> widget mapping is as follows: string -> textField, bool -> checkbox, time.Time -> datetimeField, int -> numberField; nested structs are also converted and added to the form.
func (*Form) AddCss ¶
AddCss add a CSS value (in the form of option-value - e.g.: border - auto) to the form.
func (*Form) DeleteParam ¶
DeleteParm removes the parameter identified by key from form parameters list.
func (*Form) Elements ¶
func (f *Form) Elements(elems ...FormElement) *Form
Elements adds the provided elements to the form.
func (*Form) Field ¶
func (f *Form) Field(name string) fields.FieldInterface
Field returns the field identified by name. It returns an empty field if it is missing.
func (*Form) FieldSet ¶
func (f *Form) FieldSet(name string) *FieldSetType
Field returns the field identified by name. It returns an empty field if it is missing.
func (*Form) GenChoices ¶
func (f *Form) GenChoices(lenType interface{}, fnType interface{}) interface{}
func (*Form) GenChoicesForField ¶
func (*Form) NewFieldSet ¶
func (f *Form) NewFieldSet(name string, elems ...fields.FieldInterface) *FieldSetType
FieldSet creates and returns a new FieldSetType with the given name and list of fields. Every method for FieldSetType objects returns the object itself, so that call can be chained.
func (*Form) RemoveClass ¶
RemoveClass removes the given class (if present) from the Form.
func (*Form) RemoveElement ¶
RemoveElement removes an element (identified by name) from the Form.
func (*Form) Render ¶
Render executes the internal template and renders the form, returning the result as a template.HTML object embeddable in any other template.
func (*Form) Valid ¶
func (f *Form) Valid(args ...string) (valid *validation.Validation, passed bool)
Directories
¶
Path | Synopsis |
---|---|
This package provides basic constants used by go-form-it packages.
|
This package provides basic constants used by go-form-it packages. |
This package contains the base logic for the creation and rendering of field widgets.
|
This package contains the base logic for the creation and rendering of field widgets. |