fields

package
v1.6.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2021 License: MIT Imports: 9 Imported by: 5

Documentation

Overview

Package fields This package provides all the input fields logic and customization methods.

Index

Constants

View Source
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

func ConvertTime(v interface{}) (time.Time, bool)

Types

type ChoiceIndex

type ChoiceIndex struct {
	Group string
	Index int
}

type Field

type Field struct {
	Type       string
	Tmpl       string
	Widget     widgets.WidgetInterface // Public Widget field for widget customization
	CurrName   string
	OrigName   string
	Class      common.HTMLAttrValues
	ID         string
	Params     map[string]interface{}
	CSS        map[string]string
	Label      string
	LabelClass common.HTMLAttrValues
	Tag        common.HTMLAttrValues
	Value      string
	Helptext   string
	Errors     []string
	Additional map[string]interface{}
	Choices    interface{}
	ChoiceKeys map[string]ChoiceIndex
	AppendData map[string]interface{}
	TmplStyle  string
	Format     string
	Language   string
	// contains filtered or unexported fields
}

Field is a generic type containing all data associated to an input field.

func Button

func Button(name string, text string) *Field

Button creates a default generic button

func Checkbox

func Checkbox(name string, checked bool) *Field

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 CheckboxFieldFromInstance

func CheckboxFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string, useFieldValue bool, args ...func(string) string) *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 ColorField(name string) *Field

func DateField

func DateField(name string) *Field

DateField creates a default date input field with the given name.

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

func DatetimeField(name string) *Field

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 EmailField(name string) *Field

func FieldWithType

func FieldWithType(name, t string) *Field

FieldWithType creates an empty field of the given type and identified by name.

func FileField added in v1.4.0

func FileField(name string) *Field

func HiddenField

func HiddenField(name string) *Field

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 ImageField(name string) *Field

func MonthField added in v1.4.0

func MonthField(name string) *Field

func NumberField

func NumberField(name string) *Field

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

func PasswordField(name string) *Field

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

func RangeField(name string, min, max, step int) *Field

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

func ResetButton(name string, text string) *Field

ResetButton creates a default reset button with the provided name and text.

func SearchField added in v1.4.0

func SearchField(name string) *Field

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

func StaticField(name, content string) *Field

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

func SubmitButton(name string, text string) *Field

SubmitButton creates a default button with the provided name and text.

func TelField added in v1.4.0

func TelField(name string) *Field

func TextAreaField

func TextAreaField(name string, rows, cols int) *Field

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 TextField

func TextField(name string, typ ...string) *Field

TextField creates a default text input field based on the provided name.

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 TimeField

func TimeField(name string) *Field

TimeField creates a default time input field with the given name.

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 UrlField added in v1.4.0

func UrlField(name string) *Field

func WeekField added in v1.4.0

func WeekField(name string) *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) Data added in v1.3.1

func (f *Field) Data() map[string]interface{}

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) Element added in v1.4.0

func (f *Field) Element() *config.Element

func (*Field) Enabled

func (f *Field) Enabled() FieldInterface

Enabled removes the "disabled" tag from the field, making it responsive.

func (*Field) Lang added in v1.4.0

func (f *Field) Lang() string

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) Name

func (f *Field) Name() string

Name returns the name of the field.

func (*Field) OriginalName added in v1.4.0

func (f *Field) OriginalName() string

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) Render

func (f *Field) Render() template.HTML

Render packs all data and executes widget render method.

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) SetData

func (f *Field) SetData(key string, value interface{})

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) SetLang added in v1.4.0

func (f *Field) SetLang(lang string)

func (*Field) SetName added in v1.4.0

func (f *Field) SetName(name string)

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) SetStyle

func (f *Field) SetStyle(style string) FieldInterface

SetStyle sets the style (e.g.: BASE, BOOTSTRAP) of the field, correctly populating the Widget field.

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) SetTmpl

func (f *Field) SetTmpl(tmpl string, style ...string) FieldInterface

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.

func (*Field) String

func (f *Field) String() string

type FieldInterface

type FieldInterface interface {
	Name() string
	OriginalName() string
	SetName(string)
	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
	SetStyle(style string) FieldInterface
	SetLabel(label string) FieldInterface
	AddLabelClass(class string) FieldInterface
	RemoveLabelClass(class string) FieldInterface
	SetValue(value string) FieldInterface
	Disabled() FieldInterface
	Enabled() FieldInterface
	SetTmpl(tmpl string, style ...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

type InputChoice struct {
	ID, Val string
	Checked bool
}

InputChoice ID - Value pair used to define an option for select and redio input fields.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL