Documentation ¶
Overview ¶
This package provides all the input fields logic and customization methods.
Index ¶
- Constants
- type Field
- func Button(name string, text string) *Field
- func Checkbox(name string, checked bool) *Field
- func CheckboxFromInstance(i interface{}, fieldNo int, name string, options map[string]struct{}) *Field
- func DateField(name string) *Field
- func DateFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func DatetimeField(name string) *Field
- func DatetimeFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func FieldWithType(name, t string) *Field
- func HiddenField(name string) *Field
- func HiddenFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func NumberField(name string) *Field
- func NumberFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func PasswordField(name string) *Field
- func PasswordFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func RadioField(name string, choices []InputChoice) *Field
- func RadioFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func RangeField(name string, min, max, step int) *Field
- func RangeFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func ResetButton(name string, text string) *Field
- func SelectField(name string, choices map[string][]InputChoice) *Field
- func SelectFieldFromInstance(i interface{}, fieldNo int, name string, options map[string]struct{}) *Field
- func StaticField(name, content string) *Field
- func StaticFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func SubmitButton(name string, text string) *Field
- func TextAreaField(name string, rows, cols int) *Field
- func TextAreaFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func TextField(name string) *Field
- func TextFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func TimeField(name string) *Field
- func TimeFieldFromInstance(i interface{}, fieldNo int, name string) *Field
- func (f *Field) AddClass(class string) FieldInterface
- func (f *Field) AddCss(key, value 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) DeleteParam(key string) FieldInterface
- func (f *Field) Disabled() FieldInterface
- func (f *Field) Enabled() FieldInterface
- func (f *Field) MultipleChoice() FieldInterface
- func (f *Field) Name() string
- func (f *Field) RemoveClass(class string) FieldInterface
- func (f *Field) RemoveCss(key 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) SetHelptext(text string) FieldInterface
- func (f *Field) SetId(id string) FieldInterface
- func (f *Field) SetLabel(label string) FieldInterface
- func (f *Field) SetParam(key, value string) FieldInterface
- func (f *Field) SetRadioChoices(choices []InputChoice) FieldInterface
- func (f *Field) SetSelectChoices(choices map[string][]InputChoice) FieldInterface
- func (f *Field) SetStyle(style string) FieldInterface
- func (f *Field) SetText(text string) FieldInterface
- func (f *Field) SetValue(value string) FieldInterface
- func (f *Field) SingleChoice() FieldInterface
- type FieldInterface
- type InputChoice
Constants ¶
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 Checkbox ¶
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 DateFieldFromInstance ¶
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 ¶
DatetimeField creates a default datetime input field with the given name.
func DatetimeFieldFromInstance ¶
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 ¶
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 ¶
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 ¶
NumberField craetes a default number field with the provided name.
func NumberFieldFromInstance ¶
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 ¶
PasswordField creates a default password text input field based on the provided name.
func PasswordFieldFromInstance ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
StaticField returns a static field with the provided name and content
func StaticFieldFromInstance ¶
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 ¶
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 ¶
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 TextFieldFromInstance ¶
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 TimeFieldFromInstance ¶
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) 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) 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.