fields

package
v0.0.0-...-fdf12c4 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2016 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

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

Index

Constants

View Source
const (
	DATETIME_FORMAT = "2006-01-02T15: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

This section is empty.

Types

type Field

type Field struct {
	Widget widgets.WidgetInterface // Public Widget field for widget customization
	// 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 CheckboxFromInstance

func CheckboxFromInstance(i interface{}, fieldNo int, name string, 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. It uses i object's [fieldNo]-th field content (if any) to override the "checked" option in the options map and check the field.

func DateField

func DateField(name string) *Field

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

func DateFieldFromInstance

func DateFieldFromInstance(i interface{}, fieldNo int, name string) *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. It also uses i object's [fieldNo]-th field content (if any) to override the "form_value" option and fill the HTML field.

func DatetimeField

func DatetimeField(name string) *Field

DatetimeField creates a default datetime input field with the given name.

func DatetimeFieldFromInstance

func DatetimeFieldFromInstance(i interface{}, fieldNo int, name string) *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. It also uses i object's [fieldNo]-th field content (if any) to override the "form_value" option and fill the HTML field.

func FieldWithType

func FieldWithType(name, t string) *Field

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

func HiddenField

func HiddenField(name string) *Field

HiddenField creates a default hidden input field based on the provided name.

func HiddenFieldFromInstance

func HiddenFieldFromInstance(i interface{}, fieldNo int, name string) *Field

HiddenFieldFromInstance creates and initializes a hidden field based on its name, the reference object instance and field number. It uses i object's [fieldNo]-th field content to set the field content.

func NumberField

func NumberField(name string) *Field

NumberField craetes a default number field with the provided name.

func NumberFieldFromInstance

func NumberFieldFromInstance(i interface{}, fieldNo int, name string) *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. It also uses i object's [fieldNo]-th field content (if any) to override the "form_value" option and fill the HTML 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(i interface{}, fieldNo int, name string) *Field

PasswordFieldFromInstance creates and initializes a password field based on its name, the reference object instance and field number. It uses i object's [fieldNo]-th field content to set the field content.

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(i interface{}, fieldNo int, name 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>. It also uses i object's [fieldNo]-th field content (if any) to override the "form_value" option and fill the HTML field.

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(i interface{}, fieldNo int, name string) *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. It also uses i object's [fieldNo]-th field content (if any) to override the "form_value" option and fill the HTML field.

func ResetButton

func ResetButton(name string, text string) *Field

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

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(i interface{}, fieldNo int, name string, options map[string]struct{}) *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. It also uses i object's [fieldNo]-th field content (if any) to override the "form_value" option and fill the HTML field.

func StaticField

func StaticField(name, content string) *Field

StaticField returns a static field with the provided name and content

func StaticFieldFromInstance

func StaticFieldFromInstance(i interface{}, fieldNo int, name string) *Field

RadioFieldFromInstance creates and initializes a radio field based on its name, the reference object instance and field number. It uses i object's [fieldNo]-th field content (if any) to set the field content.

func SubmitButton

func SubmitButton(name string, text string) *Field

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

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(i interface{}, fieldNo int, name string) *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. It also uses i object's [fieldNo]-th field content to set the field content.

func TextField

func TextField(name string) *Field

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

func TextFieldFromInstance

func TextFieldFromInstance(i interface{}, fieldNo int, name string) *Field

TextFieldFromInstance creates and initializes a text field based on its name, the reference object instance and field number. It uses i object's [fieldNo]-th field content to set the field content.

func TimeField

func TimeField(name string) *Field

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

func TimeFieldFromInstance

func TimeFieldFromInstance(i interface{}, fieldNo int, name string) *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. It also uses i object's [fieldNo]-th field content (if any) to override the "form_value" option and fill the HTML field.

func (*Field) AddClass

func (f *Field) AddClass(class string) FieldInterface

AddClass adds a class to the field.

func (*Field) AddCss

func (f *Field) AddCss(key, value string) FieldInterface

AddCss adds a custom CSS style 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

SetLablClass allows to define custom classes for the label.

func (*Field) AddSelected

func (f *Field) AddSelected(opt ...string) FieldInterface

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

func (f *Field) Name() string

Name returns the name of 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) RemoveCss

func (f *Field) RemoveCss(key string) FieldInterface

RemoveCss removes CSS options identified by key from the field.

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

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

func (f *Field) SetHelptext(text string) FieldInterface

SetHelptext saves the field helptext.

func (*Field) SetId

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

func (f *Field) SetParam(key, value string) FieldInterface

SetParam adds a parameter (defined as key-value pair) in the field.

func (*Field) SetRadioChoices

func (f *Field) SetRadioChoices(choices []InputChoice) FieldInterface

SetRadioChoices sets an array of InputChoice objects as the possible choices for a radio field. It has no effect if type is not RADIO.

func (*Field) SetSelectChoices

func (f *Field) SetSelectChoices(choices map[string][]InputChoice) FieldInterface

SetSelectChoices 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) 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) 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
	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, value string) 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
	SetHelptext(text string) FieldInterface
	AddError(err string) FieldInterface
	MultipleChoice() FieldInterface
	SingleChoice() FieldInterface
	AddSelected(opt ...string) FieldInterface
	RemoveSelected(opt string) FieldInterface
	SetSelectChoices(choices map[string][]InputChoice) FieldInterface
	SetRadioChoices(choices []InputChoice) FieldInterface
	SetText(text string) FieldInterface
}

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
}

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