textbox

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package textbox implements textbox-like form controls.

See Textbox for a description of the basic operation of textboxes. All other textboxes inherit from it.

Index

Constants

View Source
const (
	DefaultType  = "text"
	PasswordType = "password"
	SearchType   = "search"
	NumberType   = "number" // Puts little arrows in box, will need to widen it.
	EmailType    = "email"  // see TextEmail. Prevents submission of RFC5322 email addresses (Gogh Fir <gf@example.com>)
	TelType      = "tel"
	UrlType      = "url"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DateI

type DateI interface {
	TextboxI
	SetFormats(formats []string) DateI
	Date() time.Time
	Formats() []string
}

type DateTextbox

type DateTextbox struct {
	Textbox
	// contains filtered or unexported fields
}

DateTextbox is a textbox that only permits dates and/or times to be entered into it.

Dates and times will be converted to Browser local time.

func GetDateTextbox

func GetDateTextbox(c page.ControlI, id string) *DateTextbox

GetDateTextbox is a convenience method to return the control with the given id from the page.

func NewDateTextbox

func NewDateTextbox(parent page.ControlI, id string) *DateTextbox

NewDateTextbox creates a new DateTextbox textbox.

func (*DateTextbox) Date

func (d *DateTextbox) Date() time.Time

Date returns the value as a time.Time value. If a bad value was entered into the textbox, it will return an empty value.

func (*DateTextbox) Deserialize

func (d *DateTextbox) Deserialize(dec page.Decoder)

Deserialize recreates the control from the pagestate

func (*DateTextbox) Formats

func (d *DateTextbox) Formats() []string

Formats returns the format string specified previously

func (*DateTextbox) Init

func (d *DateTextbox) Init(parent page.ControlI, id string)

Init initializes the control.

func (*DateTextbox) Serialize

func (d *DateTextbox) Serialize(e page.Encoder)

Serialize encodes the control into the pagestate

func (*DateTextbox) SetDate

func (d *DateTextbox) SetDate(t time.Time)

SetDate will set the textbox to the give time

func (*DateTextbox) SetFormats

func (d *DateTextbox) SetFormats(formats []string) DateI

SetFormats sets the format of the text allowed. The format is any allowable format that datetime or time can convert.

func (*DateTextbox) SetText

func (d *DateTextbox) SetText(s string) page.ControlI

SetText sets the DateTime to the given text. If you attempt set the text to something that is not convertible to a date, an empty string will be entered. The resulting datetime will be in UTC time. Use SetDate if you want to make sure the date is in a certain timezone.

func (*DateTextbox) SetValue

func (d *DateTextbox) SetValue(val interface{}) page.ControlI

SetValue will set the DateTextbox to the given value if possible.

func (*DateTextbox) UpdateFormValues

func (d *DateTextbox) UpdateFormValues(ctx context.Context)

func (*DateTextbox) Value

func (d *DateTextbox) Value() interface{}

Value returns the value as an interface, but the underlying value will be a datetime. If a bad value was entered into the textbox, it will return an empty datetime.

type DateTextboxCreator

type DateTextboxCreator struct {
	// ID is the control id of the html widget and must be unique to the page
	ID string
	// Placeholder is the placeholder attribute of the textbox and shows as help text inside the field
	Placeholder string
	// Type is the type attribute of the textbox
	Type string
	// MinLength is the minimum number of characters that the user is required to enter. If the
	// length is less than this number, a validation error will be shown.
	MinLength int
	// MaxLength is the maximum number of characters that the user is required to enter. If the
	// length is more than this number, a validation error will be shown.
	MaxLength int
	// ColumnCount is the number of characters wide the textbox will be, and becomes the width attribute in the tag.
	// The actual width is browser dependent. For better control, use a width style property.
	ColumnCount int
	// ReadOnly sets the readonly attribute of the textbox, which prevents it from being changed by the user.
	ReadOnly bool
	// SaveState will save the text in the textbox, to be restored if the user comes back to the page.
	// It is particularly helpful when the textbox is being used to filter the results of a query, so that
	// when the user comes back to the page, he does not have to type the filter text again.
	SaveState bool
	// Text is the initial value of the textbox. Often its best to load the value in a separate Load step after creating the control.
	Text string
	// Formats is the time.format strings to use to decode the text into a date or to display the date. By default it is datetime.UsDateTime.
	Formats []string

	page.ControlOptions
}

DateTextboxCreator creates an date textbox. Pass it to AddControls of a control, or as a Child of a FormFieldWrapper.

func (DateTextboxCreator) Create

Create creates a new control from the creator.

func (DateTextboxCreator) Init

func (c DateTextboxCreator) Init(ctx context.Context, ctrl DateI)

Init initializes the creator.

type DateValidator

type DateValidator struct {
	Message string
}

DateValidator specifies the message to show when the date is not validated.

func (DateValidator) Validate

func (v DateValidator) Validate(c page.ControlI, s string) (msg string)

Validate is called by the framework to validate the control.

type EmailI

type EmailI interface {
	TextboxI
	SetMaxItemCount(count int) EmailI
}

type EmailTextbox

type EmailTextbox struct {
	Textbox
	// contains filtered or unexported fields
}

EmailTextbox is a Textbox control that validates for email addresses. It can accept multiple addresses separated by commas, and can accept any address in RFC5322 format (Barry Gibbs <bg@example.com>) making it useful for people copying addresses out of an email client and pasting into the field.

func GetEmailTextbox

func GetEmailTextbox(c page.ControlI, id string) *EmailTextbox

GetEmailTextbox is a convenience method to return the control with the given id from the page.

func NewEmailTextbox

func NewEmailTextbox(parent page.ControlI, id string) *EmailTextbox

NewEmailTextbox creates a new textbox that validates its input as an email address. multi will allow the textbox to accept multiple email addresses separated by a comma.

func (*EmailTextbox) Addresses

func (t *EmailTextbox) Addresses() (ret []string)

Addresses returns a slice of the individual addresses entered, stripped of any extra text entered.

func (*EmailTextbox) Deserialize

func (t *EmailTextbox) Deserialize(dec page.Decoder)

func (*EmailTextbox) Init

func (t *EmailTextbox) Init(parent page.ControlI, id string)

func (*EmailTextbox) Serialize

func (t *EmailTextbox) Serialize(e page.Encoder)

func (*EmailTextbox) SetMaxItemCount

func (t *EmailTextbox) SetMaxItemCount(max int) EmailI

SetMaxItemCount increases the number of email addresses accepted by the field.

func (*EmailTextbox) UpdateFormValues

func (t *EmailTextbox) UpdateFormValues(ctx context.Context)

UpdateFormValues is used by the framework to cause the control to retrieve its values from the form

func (*EmailTextbox) Validate

func (t *EmailTextbox) Validate(ctx context.Context) bool

type EmailTextboxCreator

type EmailTextboxCreator struct {
	// ID is the control id of the html widget and must be unique to the page
	ID string
	// Placeholder is the placeholder attribute of the textbox and shows as help text inside the field
	Placeholder string
	// Type is the type attribute of the textbox
	Type string
	// MinLength is the minimum number of characters that the user is required to enter. If the
	// length is less than this number, a validation error will be shown.
	MinLength int
	// MaxLength is the maximum number of characters that the user is required to enter. If the
	// length is more than this number, a validation error will be shown.
	MaxLength int
	// ColumnCount is the number of characters wide the textbox will be, and becomes the width attribute in the tag.
	// The actual width is browser dependent. For better control, use a width style property.
	ColumnCount int
	// ReadOnly sets the readonly attribute of the textbox, which prevents it from being changed by the user.
	ReadOnly bool
	// SaveState will save the text in the textbox, to be restored if the user comes back to the page.
	// It is particularly helpful when the textbox is being used to filter the results of a query, so that
	// when the user comes back to the page, he does not have to type the filter text again.
	SaveState bool
	// Text is the initial value of the textbox. Often its best to load the value in a separate Load step after creating the control.
	Text string
	// MaxItemCount is the maximum number of email addresses allowed to be entered, separated by commas
	// By default it allows only 1.
	MaxItemCount int

	page.ControlOptions
}

EmailTextboxCreator creates an email textbox. Pass it to AddControls of a control, or as a Child of a FormFieldWrapper.

func (EmailTextboxCreator) Create

func (EmailTextboxCreator) Init

func (c EmailTextboxCreator) Init(ctx context.Context, ctrl EmailI)

type FloatI

type FloatI interface {
	TextboxI
	SetMinValue(minValue float64, invalidMessage string) FloatI
	SetMaxValue(maxValue float64, invalidMessage string) FloatI
}

type FloatLimit

type FloatLimit struct {
	Value          float64
	InvalidMessage string
}

type FloatTextbox

type FloatTextbox struct {
	Textbox
}

FloatTextbox is a textbox control that expects a floating-point value and does server-side validation on min and max values. It sets the inputmode to "decimal" to inform mobile browsers to expect decimal input.

If you would like to have client-side validation and spinner buttons, call SetType(NumberType), and set the min, max, and step attributes accordingly. The step attribute is particularly important to set to a decimal value, since by default, numeric text fields have a step of 1 and do not allow decimal input.

func GetFloatTextbox

func GetFloatTextbox(c page.ControlI, id string) *FloatTextbox

GetFloatTextbox is a convenience method to return the control with the given id from the page.

func NewFloatTextbox

func NewFloatTextbox(parent page.ControlI, id string) *FloatTextbox

func (*FloatTextbox) Float32

func (t *FloatTextbox) Float32() float32

Float32 returns the value as a float32.

func (*FloatTextbox) Float64

func (t *FloatTextbox) Float64() float64

Float64 returns the value as a float64.

func (*FloatTextbox) Init

func (t *FloatTextbox) Init(parent page.ControlI, id string)

Init is called by the framework, and subclasses of the FloatTextbox.

func (*FloatTextbox) SetFloat32

func (t *FloatTextbox) SetFloat32(v float32) *FloatTextbox

func (*FloatTextbox) SetFloat64

func (t *FloatTextbox) SetFloat64(v float64) *FloatTextbox

func (*FloatTextbox) SetMaxValue

func (t *FloatTextbox) SetMaxValue(maxValue float64, invalidMessage string) FloatI

func (*FloatTextbox) SetMinValue

func (t *FloatTextbox) SetMinValue(minValue float64, invalidMessage string) FloatI

func (*FloatTextbox) SetValue

func (t *FloatTextbox) SetValue(v interface{}) page.ControlI

func (*FloatTextbox) Value

func (t *FloatTextbox) Value() interface{}

type FloatTextboxCreator

type FloatTextboxCreator struct {
	// ID is the control id of the html widget and must be unique to the page
	ID string
	// Placeholder is the placeholder attribute of the textbox and shows as help text inside the field
	Placeholder string
	// Type is the type attribute of the textbox
	Type string
	// MinLength is the minimum number of characters that the user is required to enter. If the
	// length is less than this number, a validation error will be shown.
	MinLength int
	// MaxLength is the maximum number of characters that the user is required to enter. If the
	// length is more than this number, a validation error will be shown.
	MaxLength int
	// ColumnCount is the number of characters wide the textbox will be, and becomes the width attribute in the tag.
	// The actual width is browser dependent. For better control, use a width style property.
	ColumnCount int
	// RowCount creates a multi-line textarea with the given number of rows. By default the
	// textbox will expand vertically by this number of lines. Use a height style property for
	// better control of the height of a textbox.
	RowCount int
	// ReadOnly sets the readonly attribute of the textbox, which prevents it from being changed by the user.
	ReadOnly bool
	// SaveState will save the text in the textbox, to be restored if the user comes back to the page.
	// It is particularly helpful when the textbox is being used to filter the results of a query, so that
	// when the user comes back to the page, he does not have to type the filter text again.
	SaveState bool
	// MinValue is the minimum value the user can enter. If the user does not
	// enter at least this amount, or enters something that is not an integer, it will fail validation
	// and the FormFieldWrapper will show an error.
	MinValue *FloatLimit
	// MaxValue is the maximum value the user can enter. If the user enter more
	// than this amount, or enters something that is not an integer, it will fail validation
	// and the FormFieldWrapper will show an error.
	MaxValue *FloatLimit
	// Value is the initial value of the textbox. Often its best to load the value in a separate Load step after creating the control.
	Value interface{}

	page.ControlOptions
}

FloatTextboxCreator creates a textbox that only accepts numbers. Pass it to AddControls of a control, or as a Child of a FormFieldWrapper.

func (FloatTextboxCreator) Create

Create is called by the framework to create a new control from the Creator. You do not normally need to call this.

func (FloatTextboxCreator) Init

func (c FloatTextboxCreator) Init(ctx context.Context, ctrl FloatI)

Init is called by implementations of Textboxes to initialize a control with the creator. You do not normally need to call this.

type FloatValidator

type FloatValidator struct {
	Message string
}

func (FloatValidator) Validate

func (v FloatValidator) Validate(c page.ControlI, s string) (msg string)

type IntValidator

type IntValidator struct {
	Message string
}

func (IntValidator) Validate

func (v IntValidator) Validate(c page.ControlI, s string) (msg string)

type IntegerI

type IntegerI interface {
	TextboxI
	SetMinValue(minValue int, invalidMessage string) IntegerI
	SetMaxValue(maxValue int, invalidMessage string) IntegerI
}

type IntegerLimit

type IntegerLimit struct {
	Value          int
	InvalidMessage string
}

type IntegerTextbox

type IntegerTextbox struct {
	Textbox
	// contains filtered or unexported fields
}

IntegerTextbox is a textbox that only permits integers. It does server-side validation on a minimum and maximum value when set. It sets the inputmode attribute on the html textbox to "numeric" to inform mobile browsers that numeric data is expected. If you would like client-side validation and up and down spinner arrows, call SetType(NumberType), and set the min and max attributes.

func GetIntegerTextbox

func GetIntegerTextbox(c page.ControlI, id string) *IntegerTextbox

GetIntegerTextbox is a convenience method to return the control with the given id from the page.

func NewIntegerTextbox

func NewIntegerTextbox(parent page.ControlI, id string) *IntegerTextbox

func (*IntegerTextbox) Init

func (t *IntegerTextbox) Init(parent page.ControlI, id string)

func (*IntegerTextbox) Int

func (t *IntegerTextbox) Int() int

func (*IntegerTextbox) Int64

func (t *IntegerTextbox) Int64() int64

func (*IntegerTextbox) SetInt

func (t *IntegerTextbox) SetInt(v int) IntegerI

func (*IntegerTextbox) SetMaxValue

func (t *IntegerTextbox) SetMaxValue(maxValue int, invalidMessage string) IntegerI

SetMaxValue creates a validator that makes sure the value of the text box is at most the given value. Specify your own error message, or leave the error message blank and a standard error message will be presented if the value is not valid.

func (*IntegerTextbox) SetMinValue

func (t *IntegerTextbox) SetMinValue(minValue int, invalidMessage string) IntegerI

SetMinValue creates a validator that makes sure the value of the text box is at least the given value. Specify your own error message, or leave the error message blank and a standard error message will be presented if the value is not valid.

func (*IntegerTextbox) SetValue

func (t *IntegerTextbox) SetValue(v interface{}) page.ControlI

func (*IntegerTextbox) Value

func (t *IntegerTextbox) Value() interface{}

type IntegerTextboxCreator

type IntegerTextboxCreator struct {
	// ID is the control id of the html widget and must be unique to the page
	ID string
	// Placeholder is the placeholder attribute of the textbox and shows as help text inside the field
	Placeholder string
	// Type is the type attribute of the textbox
	Type string
	// MinLength is the minimum number of characters that the user is required to enter. If the
	// length is less than this number, a validation error will be shown.
	MinLength int
	// MaxLength is the maximum number of characters that the user is required to enter. If the
	// length is more than this number, a validation error will be shown.
	MaxLength int
	// ColumnCount is the number of characters wide the textbox will be, and becomes the width attribute in the tag.
	// The actual width is browser dependent. For better control, use a width style property.
	ColumnCount int
	// RowCount creates a multi-line textarea with the given number of rows. By default the
	// textbox will expand vertically by this number of lines. Use a height style property for
	// better control of the height of a textbox.
	RowCount int
	// ReadOnly sets the readonly attribute of the textbox, which prevents it from being changed by the user.
	ReadOnly bool
	// SaveState will save the text in the textbox, to be restored if the user comes back to the page.
	// It is particularly helpful when the textbox is being used to filter the results of a query, so that
	// when the user comes back to the page, he does not have to type the filter text again.
	SaveState bool
	// MinValue is the minimum value the user can enter. If the user does not
	// enter at least this amount, or enters something that is not an integer, it will fail validation
	// and the FormFieldWrapper will show an error.
	MinValue *IntegerLimit
	// MaxValue is the maximum value the user can enter. If the user enter more
	// than this amount, or enters something that is not an integer, it will fail validation
	// and the FormFieldWrapper will show an error.
	MaxValue *IntegerLimit
	// Value is the initial value of the textbox. Often its best to load the value in a separate Load step after creating the control.
	Value interface{}

	page.ControlOptions
}

IntegerTextboxCreator creates an integer textbox. Pass it to AddControls of a control, or as a Child of a FormFieldWrapper.

func (IntegerTextboxCreator) Create

Create is called by the framework to create a new control from the Creator. You do not normally need to call this.

func (IntegerTextboxCreator) Init

func (c IntegerTextboxCreator) Init(ctx context.Context, ctrl IntegerI)

Init is called by implementations of Textboxes to initialize a control with the creator. You do not normally need to call this.

type MaxFloatValidator

type MaxFloatValidator struct {
	MaxValue float64
	Message  string
}

func (MaxFloatValidator) Validate

func (v MaxFloatValidator) Validate(c page.ControlI, s string) (msg string)

type MaxIntValidator

type MaxIntValidator struct {
	MaxValue int
	Message  string
}

func (MaxIntValidator) Validate

func (v MaxIntValidator) Validate(c page.ControlI, s string) (msg string)

type MaxLengthValidator

type MaxLengthValidator struct {
	Length  int
	Message string
}

MaxLengthValidator is a Validater to test that the user did not enter too many characters.

func (MaxLengthValidator) Validate

func (v MaxLengthValidator) Validate(c page.ControlI, s string) (msg string)

Validate runs the Validate logic to validate the control value.

type MinFloatValidator

type MinFloatValidator struct {
	MinValue float64
	Message  string
}

func (MinFloatValidator) Validate

func (v MinFloatValidator) Validate(c page.ControlI, s string) (msg string)

type MinIntValidator

type MinIntValidator struct {
	MinValue int
	Message  string
}

func (MinIntValidator) Validate

func (v MinIntValidator) Validate(c page.ControlI, s string) (msg string)

type MinLengthValidator

type MinLengthValidator struct {
	Length  int
	Message string
}

MinLengthValidator is a validator that checks that the user has entered a minimum length. It is set up automatically by calling SetMinValue.

func (MinLengthValidator) Validate

func (v MinLengthValidator) Validate(c page.ControlI, s string) (msg string)

Validate runs the Validate logic to validate the control value.

type PasswordI

type PasswordI interface {
	TextboxI
}

PasswordI is the interface that defines a PasswordTextbox

type PasswordTextbox

type PasswordTextbox struct {
	Textbox
}

PasswordTextbox is a Textbox for passwords. It has the "password" type attribute, and it is specially controlled so that the password value is never stored in cleartext, either through the pagestate store or through the state store.

func GetPasswordTextbox

func GetPasswordTextbox(c page.ControlI, id string) *PasswordTextbox

GetPasswordTextbox is a convenience method to return the control with the given id from the page.

func NewPasswordTextbox

func NewPasswordTextbox(parent page.ControlI, id string) *PasswordTextbox

NewPasswordTextbox creates a new PasswordTextbox

func (*PasswordTextbox) Init

func (t *PasswordTextbox) Init(parent page.ControlI, id string)

Init is called by the framework to initialize the control. Only subclasses need to call it.

func (*PasswordTextbox) SaveState

func (t *PasswordTextbox) SaveState(_ context.Context, _ bool)

SaveState normally is used to save the text of the control to restore it if the page is returned to. This version panics, so that you never SaveState on a password text box.

func (*PasswordTextbox) Serialize

func (t *PasswordTextbox) Serialize(e page.Encoder)

Serialize is used by the framework to serialize the textbox into the pagestate.

This special override prevents the value of the password from ever getting put into the pagestate store.

type PasswordTextboxCreator

type PasswordTextboxCreator struct {
	// ID is the control id of the html widget and must be unique to the page
	ID string
	// Placeholder is the placeholder attribute of the textbox and shows as help text inside the field
	Placeholder string
	// MinLength is the minimum number of characters that the user is required to enter. If the
	// length is less than this number, a validation error will be shown.
	MinLength int
	// MaxLength is the maximum number of characters that the user is required to enter. If the
	// length is more than this number, a validation error will be shown.
	MaxLength int
	// ColumnCount is the number of characters wide the textbox will be, and becomes the width attribute in the tag.
	// The actual width is browser dependent. For better control, use a width style property.
	ColumnCount int
	// Text is the initial value of the textbox. Often it is best to load the value in a separate Load step after creating the control.
	Text string

	page.ControlOptions
}

PasswordTextboxCreator creates a PasswordTextbox. Pass it to AddControls of a control, or as a Child of a FormFieldWrapper.

func (PasswordTextboxCreator) Create

Create is called by the framework to turn the PasswordTextboxCreator into a control. You do not normally need to call it.

func (PasswordTextboxCreator) Init

func (c PasswordTextboxCreator) Init(ctx context.Context, ctrl PasswordI)

Init is called by the framework to initialize a newly created PasswordTextbox. You do not normally need to call it.

type PhoneI

type PhoneI interface {
	TextboxI
}

type PhoneTextbox

type PhoneTextbox struct {
	Textbox
}

PhoneTextbox is a Textbox control that validates for phone numbers.

func GetPhoneTextbox

func GetPhoneTextbox(c page.ControlI, id string) *PhoneTextbox

GetPhoneTextbox is a convenience method to return the control with the given id from the page.

func NewPhoneTextbox

func NewPhoneTextbox(parent page.ControlI, id string) *PhoneTextbox

NewPhoneTextbox creates a new textbox that validates its input as an email address. multi will allow the textbox to accept multiple email addresses separated by a comma.

func (*PhoneTextbox) Init

func (t *PhoneTextbox) Init(parent page.ControlI, id string)

func (*PhoneTextbox) Validate

func (t *PhoneTextbox) Validate(ctx context.Context) bool

type PhoneTextboxCreator

type PhoneTextboxCreator struct {
	// ID is the control id of the html widget and must be unique to the page
	ID string
	// Placeholder is the placeholder attribute of the textbox and shows as help text inside the field
	Placeholder string
	// Type is the type attribute of the textbox
	Type string
	// MinLength is the minimum number of characters that the user is required to enter. If the
	// length is less than this number, a validation error will be shown.
	MinLength int
	// MaxLength is the maximum number of characters that the user is required to enter. If the
	// length is more than this number, a validation error will be shown.
	MaxLength int
	// ColumnCount is the number of characters wide the textbox will be, and becomes the width attribute in the tag.
	// The actual width is browser dependent. For better control, use a width style property.
	ColumnCount int
	// ReadOnly sets the readonly attribute of the textbox, which prevents it from being changed by the user.
	ReadOnly bool
	// SaveState will save the text in the textbox, to be restored if the user comes back to the page.
	// It is particularly helpful when the textbox is being used to filter the results of a query, so that
	// when the user comes back to the page, he does not have to type the filter text again.
	SaveState bool
	// Text is the initial value of the textbox. Often its best to load the value in a separate Load step after creating the control.
	Text string

	page.ControlOptions
}

PhoneTextboxCreator creates an phone textbox. Pass it to AddControls of a control, or as a Child of a FormFieldWrapper.

func (PhoneTextboxCreator) Create

func (PhoneTextboxCreator) Init

func (c PhoneTextboxCreator) Init(ctx context.Context, ctrl PhoneI)

type Textbox

type Textbox struct {
	page.ControlBase
	// contains filtered or unexported fields
}

Textbox is a GoRADD control that outputs an HTML textbox control.

HTML defines two basic kinds of textbox controls. Single line textboxes are drawn using an "input" tag with a "type" attribute of "text", or one of the text-like types, like "password", "search", etc. Multiline textboxes are drawn with a textarea tag. Use [SetRowCount] to control which kind of control is drawn.

Textboxes can be validated before they are submitted to the form by using [ValidateWith] to add a Validater.

You can also set a global sanitizer to attempt to remove malicious or invalid values from the textbox. See config.GlobalSanitizer.

func GetTextbox

func GetTextbox(c page.ControlI, id string) *Textbox

GetTextbox is a convenience method to return the control with the given id from the page.

func NewTextbox

func NewTextbox(parent page.ControlI, id string) *Textbox

NewTextbox creates a new GoRADD Textbox control.

func (*Textbox) Deserialize

func (t *Textbox) Deserialize(d page.Decoder)

Deserialize is used by the pagestate serializer.

func (*Textbox) DrawInnerHtml

func (t *Textbox) DrawInnerHtml(_ context.Context, w io.Writer)

DrawInnerHtml is an internal function that renders the inner html of a tag. For a Textbox, it only draws HTML when drawing a textarea tag.

func (*Textbox) DrawingAttributes

func (t *Textbox) DrawingAttributes(ctx context.Context) html5tag.Attributes

DrawingAttributes is called by the framework to retrieve the tag's private attributes at draw time.

func (*Textbox) Init

func (t *Textbox) Init(parent page.ControlI, id string)

Init initializes a Textbox. Normally you will not call this directly.

func (*Textbox) MarshalState

func (t *Textbox) MarshalState(m page.SavedState)

MarshalState is an internal function to save the state of the control

func (*Textbox) MaxLength

func (t *Textbox) MaxLength() int

MaxLength returns the current maximum length setting.

func (*Textbox) MinLength

func (t *Textbox) MinLength() int

MinLength returns the minimum length setting.

func (*Textbox) Placeholder

func (t *Textbox) Placeholder() string

Placeholder returns the value of the placeholder.

func (*Textbox) ResetValidators

func (t *Textbox) ResetValidators()

ResetValidators removes all validators

func (*Textbox) Sanitize

func (t *Textbox) Sanitize(s string) string

Sanitize is called by the framework when taking in user input and strips it of potential malicious XSS scripts.

The default uses a global sanitizer created at startup. Override Sanitize in a subclass if you want a per-textbox sanitizer. This is a very difficult thing to get right, and depends a bit on your application on just how much you want to remove.

func (*Textbox) Serialize

func (t *Textbox) Serialize(e page.Encoder)

Serialize is used by the framework to serialize the textbox into the pagestate.

func (*Textbox) SetColumnCount

func (t *Textbox) SetColumnCount(columns int) TextboxI

SetColumnCount sets the visible width of the text control. Each table is an approximate with of a character, and is browser dependent, so its not a very good way of setting the width. The css width property is more accurate. Also, this is only the visible width, not the maximum number of characters.

func (*Textbox) SetMaxLength

func (t *Textbox) SetMaxLength(len int) *MaxLengthValidator

SetMaxLength sets the maximum length allowed in the textbox. The text will be limited by the browser, but the server side will also make sure that the text is not too big.

func (*Textbox) SetMinLength

func (t *Textbox) SetMinLength(len int) *MinLengthValidator

SetMinLength will set the minimum length permitted. If the user does not enter enough text, an error message will be displayed upon submission of the form.

func (*Textbox) SetPlaceholder

func (t *Textbox) SetPlaceholder(s string) TextboxI

SetPlaceholder will set the html placeholder attribute, which puts text in the textbox when the textbox is empty as a hint to the user of what to enter.

func (*Textbox) SetReadOnly

func (t *Textbox) SetReadOnly(r bool) TextboxI

SetReadOnly will disable editing by setting a browser attribute.

func (*Textbox) SetRowCount

func (t *Textbox) SetRowCount(rows int) TextboxI

SetRowCount sets the number of rowCount the Textbox will have. A value of 0 produces an input tag, and a value of 1 or greater produces a textarea tag.

func (*Textbox) SetText

func (t *Textbox) SetText(s string) page.ControlI

SetText sets the value of the text.

func (*Textbox) SetType

func (t *Textbox) SetType(typ string) TextboxI

SetType sets the type of textbox this is. Pass it a TextboxType* constant normally, though you can pass any string and it will become the input type

func (*Textbox) SetValue

func (t *Textbox) SetValue(v interface{}) page.ControlI

SetValue sets the text in the textbox. This satisfies the Valuer interface.

func (*Textbox) Text

func (t *Textbox) Text() string

Text returns the text entered by the user.

func (*Textbox) UnmarshalState

func (t *Textbox) UnmarshalState(m page.SavedState)

UnmarshalState is an internal function to restore the state of the control

func (*Textbox) UpdateFormValues

func (t *Textbox) UpdateFormValues(ctx context.Context)

UpdateFormValues is used by the framework to cause the control to retrieve its values from the form

func (*Textbox) Validate

func (t *Textbox) Validate(ctx context.Context) bool

Validate will first check for the IsRequired attribute, and if set, will make sure a value is in the text field. It will then check the validators in the order assigned. The first invalid value found will return false.

func (*Textbox) ValidateWith

func (t *Textbox) ValidateWith(v Validater)

ValidateWith adds a Validater to the validator list.

func (*Textbox) Value

func (t *Textbox) Value() interface{}

Value returns the user entered text in the textbox.

type TextboxCreator

type TextboxCreator struct {
	// ID is the control id of the html widget and must be unique to the page
	ID string
	// Placeholder is the placeholder attribute of the textbox and shows as help text inside the field
	Placeholder string
	// Type is the type attribute of the textbox
	Type string
	// MinLength is the minimum number of characters that the user is required to enter. If the
	// length is less than this number, a validation error will be shown.
	MinLength int
	// MaxLength is the maximum number of characters that the user is required to enter. If the
	// length is more than this number, a validation error will be shown.
	MaxLength int
	// ColumnCount is the number of characters wide the textbox will be, and becomes the width attribute in the tag.
	// The actual width is browser dependent. For better control, use a width style property.
	ColumnCount int
	// RowCount creates a multi-line textarea with the given number of rows. By default the
	// textbox will expand vertically by this number of lines. Use a height style property for
	// better control of the height of a textbox.
	RowCount int
	// ReadOnly sets the readonly attribute of the textbox, which prevents it from being changed by the user.
	ReadOnly bool
	// SaveState will save the text in the textbox, to be restored if the user comes back to the page.
	// It is particularly helpful when the textbox is being used to filter the results of a query, so that
	// when the user comes back to the page, he does not have to type the filter text again.
	SaveState bool
	// Text is the initial value of the textbox. Generally you would not use this, but rather load the value in a separate Load step after creating the control.
	Text string

	page.ControlOptions
}

TextboxCreator creates a textbox. Pass it to AddControls of a control, or as a Child of a FormFieldWrapper.

func (TextboxCreator) Create

func (c TextboxCreator) Create(ctx context.Context, parent page.ControlI) page.ControlI

Create is called by the framework to create a new control from the Creator. You do not normally need to call this.

func (TextboxCreator) Init

func (c TextboxCreator) Init(ctx context.Context, ctrl TextboxI)

Init is called by implementations of Textboxes to initialize a control with the creator. You do not normally need to call this.

type TextboxI

type TextboxI interface {
	page.ControlI
	SetType(typ string) TextboxI
	Sanitize(string) string
	SetPlaceholder(s string) TextboxI
	SetMaxLength(len int) *MaxLengthValidator
	SetMinLength(len int) *MinLengthValidator
	SetRowCount(rows int) TextboxI
	SetColumnCount(columns int) TextboxI
	SetReadOnly(r bool) TextboxI
	SetValue(interface{}) page.ControlI
}

TextboxI is the interface that all textboxes use. See the Textbox struct for details.

func GetTextboxI

func GetTextboxI(c page.ControlI, id string) TextboxI

type Validater

type Validater interface {
	// Validate evaluates the input, and returns an empty string if the input is valid, and an error string to display
	// to the user if the input does not pass the validator.
	Validate(page.ControlI, string) string
}

A Validater can be added to a Textbox to validate its input on the server side. A Textbox can have more than one Validater. A number of built-in validators are provided.

Jump to

Keyboard shortcuts

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