Documentation ¶
Overview ¶
Package fields This package provides all the input fields logic and customization methods.
Index ¶
- Constants
- func ConvertTime(v interface{}) (time.Time, bool)
- type ChoiceIndex
- type Field
- func Button(name string, text string) *Field
- func Checkbox(name string, checked bool) *Field
- func CheckboxField(name string, choices []InputChoice) *Field
- func CheckboxFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func CheckboxFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func ColorField(name string) *Field
- func DateField(name string) *Field
- func DateFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func DatetimeField(name string) *Field
- func DatetimeFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func EmailField(name string) *Field
- func FieldWithType(name, t string) *Field
- func FileField(name string) *Field
- func HiddenField(name string) *Field
- func HiddenFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func ImageField(name string) *Field
- func MonthField(name string) *Field
- func NumberField(name string) *Field
- func NumberFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func PasswordField(name string) *Field
- func PasswordFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func RadioField(name string, choices []InputChoice) *Field
- func RadioFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func RangeField(name string, min, max, step int) *Field
- func RangeFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func ResetButton(name string, text string) *Field
- func SearchField(name string) *Field
- func SelectField(name string, choices map[string][]InputChoice) *Field
- func SelectFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func StaticField(name, content string) *Field
- func StaticFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func SubmitButton(name string, text string) *Field
- func TelField(name string) *Field
- func TextAreaField(name string, rows, cols int) *Field
- func TextAreaFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func TextField(name string, typ ...string) *Field
- func TextFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func TimeField(name string) *Field
- func TimeFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, ...) *Field
- func UrlField(name string) *Field
- func WeekField(name string) *Field
- func (f *Field) AddCSS(key, value string) FieldInterface
- func (f *Field) AddChoice(key, value interface{}, checked ...bool) FieldInterface
- func (f *Field) AddClass(class string) FieldInterface
- func (f *Field) AddError(err string) FieldInterface
- func (f *Field) AddLabelClass(class string) FieldInterface
- func (f *Field) AddSelected(opt ...string) FieldInterface
- func (f *Field) AddTag(tag string) FieldInterface
- func (f *Field) Clone() config.FormElement
- func (f *Field) Data() map[string]interface{}
- func (f *Field) DeleteParam(key string) FieldInterface
- func (f *Field) Disabled() FieldInterface
- func (f *Field) Element() *config.Element
- func (f *Field) Enabled() FieldInterface
- func (f *Field) Lang() string
- func (f *Field) MultipleChoice() FieldInterface
- func (f *Field) Name() string
- func (f *Field) OriginalName() string
- func (f *Field) RemoveCSS(key string) FieldInterface
- func (f *Field) RemoveClass(class string) FieldInterface
- func (f *Field) RemoveLabelClass(class string) FieldInterface
- func (f *Field) RemoveSelected(opt string) FieldInterface
- func (f *Field) RemoveTag(tag string) FieldInterface
- func (f *Field) Render() template.HTML
- func (f *Field) SetChoices(choices interface{}, saveIndex ...bool) FieldInterface
- func (f *Field) SetData(key string, value interface{})
- func (f *Field) SetFieldCols(cols int)
- func (f *Field) SetHelptext(text string) FieldInterface
- func (f *Field) SetID(id string) FieldInterface
- func (f *Field) SetLabel(label string) FieldInterface
- func (f *Field) SetLabelCols(cols int)
- func (f *Field) SetLang(lang string)
- func (f *Field) SetName(name string)
- func (f *Field) SetParam(key string, value interface{}) FieldInterface
- func (f *Field) SetSelected(opt ...string) FieldInterface
- func (f *Field) SetTemplate(tmpl string, theme ...string) FieldInterface
- func (f *Field) SetText(text string) FieldInterface
- func (f *Field) SetTheme(theme string) FieldInterface
- func (f *Field) SetValue(value string) FieldInterface
- func (f *Field) SingleChoice() FieldInterface
- func (f *Field) String() string
- type FieldInterface
- type InputChoice
Constants ¶
const ( DATETIME_FORMAT = "2006-01-02 15:05" DATE_FORMAT = "2006-01-02" TIME_FORMAT = "15:05" )
Datetime format string to convert from time.Time objects to HTML fields and viceversa.
Variables ¶
This section is empty.
Functions ¶
func ConvertTime ¶ added in v1.4.0
Types ¶
type ChoiceIndex ¶
type Field ¶
type Field struct { Type string `json:"type" xml:"type"` Template string `json:"template" xml:"template"` CurrName string `json:"currName" xml:"currName"` OrigName string `json:"oriName" xml:"oriName"` Classes common.HTMLAttrValues `json:"classes" xml:"classes"` ID string `json:"id" xml:"id"` Params map[string]interface{} `json:"params" xml:"params"` CSS map[string]string `json:"css" xml:"css"` Label string `json:"label" xml:"label"` LabelCols int `json:"labelCols" xml:"labelCols"` FieldCols int `json:"fieldCols" xml:"fieldCols"` LabelClasses common.HTMLAttrValues `json:"labelClasses" xml:"labelClasses"` Tags common.HTMLAttrValues `json:"tags" xml:"tags"` Value string `json:"value" xml:"value"` Helptext string `json:"helpText" xml:"helpText"` Errors []string `json:"errors,omitempty" xml:"errors,omitempty"` Additional map[string]interface{} `json:"additional,omitempty" xml:"additional,omitempty"` Choices interface{} `json:"choices,omitempty" xml:"choices,omitempty"` ChoiceKeys map[string]ChoiceIndex `json:"choiceKeys,omitempty" xml:"choiceKeys,omitempty"` AppendData map[string]interface{} `json:"appendData,omitempty" xml:"appendData,omitempty"` Theme string `json:"theme" xml:"theme"` Format string `json:"format,omitempty" xml:"format,omitempty"` Language string `json:"language,omitempty" xml:"language,omitempty"` // contains filtered or unexported fields }
Field is a generic type containing all data associated to an input field.
func Checkbox ¶
Checkbox creates a default checkbox field with the provided name. It also makes it checked by default based on the checked parameter.
func CheckboxField ¶
func CheckboxField(name string, choices []InputChoice) *Field
func CheckboxFromInstance ¶
func CheckboxFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool, options map[string]struct{}) *Field
CheckboxFromInstance creates and initializes a checkbox field based on its name, the reference object instance, field number and field options.
func ColorField ¶ added in v1.4.0
func DateFieldFromInstance ¶
func DateFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool) *Field
DateFieldFromInstance creates and initializes a date field based on its name, the reference object instance and field number. This method looks for "form_min", "form_max" and "form_value" tags to add additional parameters to the field.
func DatetimeField ¶
DatetimeField creates a default datetime input field with the given name.
func DatetimeFieldFromInstance ¶
func DatetimeFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool) *Field
DatetimeFieldFromInstance creates and initializes a datetime field based on its name, the reference object instance and field number. This method looks for "form_min", "form_max" and "form_value" tags to add additional parameters to the field.
func EmailField ¶ added in v1.4.0
func FieldWithType ¶
FieldWithType creates an empty field of the given type and identified by name.
func HiddenField ¶
HiddenField creates a default hidden input field based on the provided name.
func HiddenFieldFromInstance ¶
func HiddenFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool) *Field
HiddenFieldFromInstance creates and initializes a hidden field based on its name, the reference object instance and field number.
func ImageField ¶ added in v1.4.0
func MonthField ¶ added in v1.4.0
func NumberField ¶
NumberField craetes a default number field with the provided name.
func NumberFieldFromInstance ¶
func NumberFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool) *Field
NumberFieldFromInstance creates and initializes a number field based on its name, the reference object instance and field number. This method looks for "form_min", "form_max" and "form_value" tags to add additional parameters to the field.
func PasswordField ¶
PasswordField creates a default password text input field based on the provided name.
func PasswordFieldFromInstance ¶
func PasswordFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool) *Field
PasswordFieldFromInstance creates and initializes a password field based on its name, the reference object instance and field number.
func RadioField ¶
func RadioField(name string, choices []InputChoice) *Field
RadioField creates a default radio button input field with the provided name and list of choices.
func RadioFieldFromInstance ¶
func RadioFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool, args ...func(string) string) *Field
RadioFieldFromInstance creates and initializes a radio field based on its name, the reference object instance and field number. This method looks for "form_choices" and "form_value" tags to add additional parameters to the field. "form_choices" tag is a list of <id>|<value> options, joined by "|" character; ex: "A|Option A|B|Option B" translates into 2 options: <A, Option A> and <B, Option B>.
func RangeField ¶
RangeField creates a default range field with the provided name. Min, max and step parameters define the expected behavior of the HTML field.
func RangeFieldFromInstance ¶
func RangeFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool) *Field
RangeFieldFromInstance creates and initializes a range field based on its name, the reference object instance and field number. This method looks for "form_min", "form_max", "form_step" and "form_value" tags to add additional parameters to the field.
func ResetButton ¶
ResetButton creates a default reset button with the provided name and text.
func SearchField ¶ added in v1.4.0
func SelectField ¶
func SelectField(name string, choices map[string][]InputChoice) *Field
SelectField creates a default select input field with the provided name and map of choices. Choices for SelectField are grouped by name (if <optgroup> is needed); "" group is the default one and does not trigger a <optgroup></optgroup> rendering.
func SelectFieldFromInstance ¶
func SelectFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool, options map[string]struct{}, args ...func(string) string) *Field
SelectFieldFromInstance creates and initializes a select field based on its name, the reference object instance and field number. This method looks for "form_choices" and "form_value" tags to add additional parameters to the field. "form_choices" tag is a list of <group<|<id>|<value> options, joined by "|" character; ex: "G1|A|Option A|G1|B|Option B" translates into 2 options in the same group G1: <A, Option A> and <B, Option B>. "" group is the default one.
func StaticField ¶
StaticField returns a static field with the provided name and content
func StaticFieldFromInstance ¶
func StaticFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool) *Field
StaticFieldFromInstance creates and initializes a radio field based on its name, the reference object instance and field number.
func SubmitButton ¶
SubmitButton creates a default button with the provided name and text.
func TextAreaField ¶
TextAreaField creates a default textarea input field based on the provided name and dimensions.
func TextAreaFieldFromInstance ¶
func TextAreaFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool) *Field
TextFieldFromInstance creates and initializes a text field based on its name, the reference object instance and field number. This method looks for "form_rows" and "form_cols" tags to add additional parameters to the field.
func TextFieldFromInstance ¶
func TextFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool, typ ...string) *Field
TextFieldFromInstance creates and initializes a text field based on its name, the reference object instance and field number.
func TimeFieldFromInstance ¶
func TimeFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool) *Field
TimeFieldFromInstance creates and initializes a time field based on its name, the reference object instance and field number. This method looks for "form_min", "form_max" and "form_value" tags to add additional parameters to the field.
func (*Field) AddCSS ¶ added in v1.4.0
func (f *Field) AddCSS(key, value string) FieldInterface
AddCSS adds a custom CSS style the field.
func (*Field) AddChoice ¶ added in v1.4.0
func (f *Field) AddChoice(key, value interface{}, checked ...bool) FieldInterface
func (*Field) AddClass ¶
func (f *Field) AddClass(class string) FieldInterface
AddClass adds a class to the field.
func (*Field) AddError ¶
func (f *Field) AddError(err string) FieldInterface
AddError adds an error string to the field. It's valid only for Bootstrap forms.
func (*Field) AddLabelClass ¶
func (f *Field) AddLabelClass(class string) FieldInterface
AddLabelClass allows to define custom classes for the label.
func (*Field) AddSelected ¶
func (f *Field) AddSelected(opt ...string) FieldInterface
AddSelected If the field is configured as "multiple", AddSelected adds a selected value to the field (valid for SelectFields only). It has no effect if type is not SELECT.
func (*Field) AddTag ¶
func (f *Field) AddTag(tag string) FieldInterface
AddTag adds a no-value parameter (e.g.: checked, disabled) to the field.
func (*Field) Clone ¶ added in v1.4.0
func (f *Field) Clone() config.FormElement
func (*Field) DeleteParam ¶
func (f *Field) DeleteParam(key string) FieldInterface
DeleteParam removes a parameter identified by key from the field.
func (*Field) Disabled ¶
func (f *Field) Disabled() FieldInterface
Disabled add the "disabled" tag to the field, making it unresponsive in some environments (e.g. Bootstrap).
func (*Field) Enabled ¶
func (f *Field) Enabled() FieldInterface
Enabled removes the "disabled" tag from the field, making it responsive.
func (*Field) MultipleChoice ¶
func (f *Field) MultipleChoice() FieldInterface
MultipleChoice configures the SelectField to accept and display multiple choices. It has no effect if type is not SELECT.
func (*Field) OriginalName ¶ added in v1.4.0
func (*Field) RemoveCSS ¶ added in v1.4.0
func (f *Field) RemoveCSS(key string) FieldInterface
RemoveCSS removes CSS options identified by key from the field.
func (*Field) RemoveClass ¶
func (f *Field) RemoveClass(class string) FieldInterface
RemoveClass removes a class from the field, if it was present.
func (*Field) RemoveLabelClass ¶
func (f *Field) RemoveLabelClass(class string) FieldInterface
RemoveLabelClass removes the given class from the field label.
func (*Field) RemoveSelected ¶
func (f *Field) RemoveSelected(opt string) FieldInterface
RemoveSelected If the field is configured as "multiple", AddSelected removes the selected value from the field (valid for SelectFields only). It has no effect if type is not SELECT.
func (*Field) RemoveTag ¶
func (f *Field) RemoveTag(tag string) FieldInterface
RemoveTag removes a no-value parameter from the field.
func (*Field) SetChoices ¶
func (f *Field) SetChoices(choices interface{}, saveIndex ...bool) FieldInterface
SetChoices takes as input a dictionary whose key-value entries are defined as follows: key is the group name (the empty string is the default group that is not explicitly rendered) and value is the list of choices belonging to that group. Grouping is only useful for Select fields, while groups are ignored in Radio fields. It has no effect if type is not SELECT.
func (*Field) SetFieldCols ¶ added in v1.7.0
func (*Field) SetHelptext ¶
func (f *Field) SetHelptext(text string) FieldInterface
SetHelptext saves the field helptext.
func (*Field) SetID ¶ added in v1.4.0
func (f *Field) SetID(id string) FieldInterface
SetID associates the given id to the field, overwriting any previous id.
func (*Field) SetLabel ¶
func (f *Field) SetLabel(label string) FieldInterface
SetLabel saves the label to be rendered along with the field.
func (*Field) SetLabelCols ¶ added in v1.7.0
func (*Field) SetParam ¶
func (f *Field) SetParam(key string, value interface{}) FieldInterface
SetParam adds a parameter (defined as key-value pair) in the field.
func (*Field) SetSelected ¶ added in v1.4.0
func (f *Field) SetSelected(opt ...string) FieldInterface
func (*Field) SetTemplate ¶ added in v1.8.0
func (f *Field) SetTemplate(tmpl string, theme ...string) FieldInterface
func (*Field) SetText ¶
func (f *Field) SetText(text string) FieldInterface
SetText saves the provided text as content of the field, usually a TextAreaField.
func (*Field) SetTheme ¶ added in v1.9.0
func (f *Field) SetTheme(theme string) FieldInterface
SetTheme sets the theme (e.g.: BASE, BOOTSTRAP) of the field, correctly populating the Widget field.
func (*Field) SetValue ¶
func (f *Field) SetValue(value string) FieldInterface
SetValue sets the value parameter for the field.
func (*Field) SingleChoice ¶
func (f *Field) SingleChoice() FieldInterface
SingleChoice configures the Field to accept and display only one choice (valid for SelectFields only). It has no effect if type is not SELECT.
type FieldInterface ¶
type FieldInterface interface { Name() string OriginalName() string SetName(string) SetLabelCols(cols int) SetFieldCols(cols int) Render() template.HTML AddClass(class string) FieldInterface RemoveClass(class string) FieldInterface AddTag(class string) FieldInterface RemoveTag(class string) FieldInterface SetID(id string) FieldInterface SetParam(key string, value interface{}) FieldInterface DeleteParam(key string) FieldInterface AddCSS(key, value string) FieldInterface RemoveCSS(key string) FieldInterface SetTheme(theme string) FieldInterface SetLabel(label string) FieldInterface AddLabelClass(class string) FieldInterface RemoveLabelClass(class string) FieldInterface SetValue(value string) FieldInterface Disabled() FieldInterface Enabled() FieldInterface SetTemplate(tmpl string, theme ...string) FieldInterface SetHelptext(text string) FieldInterface AddError(err string) FieldInterface MultipleChoice() FieldInterface SingleChoice() FieldInterface AddSelected(opt ...string) FieldInterface SetSelected(opt ...string) FieldInterface RemoveSelected(opt string) FieldInterface AddChoice(key, value interface{}, checked ...bool) FieldInterface SetChoices(choices interface{}, saveIndex ...bool) FieldInterface SetText(text string) FieldInterface SetData(key string, value interface{}) Data() map[string]interface{} String() string SetLang(lang string) Lang() string Clone() config.FormElement Element() *config.Element }
FieldInterface defines the interface an object must implement to be used in a form. Every method returns a FieldInterface object to allow methods chaining.
type InputChoice ¶
InputChoice ID - Value pair used to define an option for select and redio input fields.