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
- type DateI
- type DateTextbox
- func (d *DateTextbox) Date() time.Time
- func (d *DateTextbox) Deserialize(dec page.Decoder)
- func (d *DateTextbox) Formats() []string
- func (d *DateTextbox) Init(parent page.ControlI, id string)
- func (d *DateTextbox) Serialize(e page.Encoder)
- func (d *DateTextbox) SetDate(t time.Time)
- func (d *DateTextbox) SetFormats(formats []string) DateI
- func (d *DateTextbox) SetText(s string) page.ControlI
- func (d *DateTextbox) SetValue(val interface{}) page.ControlI
- func (d *DateTextbox) UpdateFormValues(ctx context.Context)
- func (d *DateTextbox) Value() interface{}
- type DateTextboxCreator
- type DateValidator
- type EmailI
- type EmailTextbox
- func (t *EmailTextbox) Addresses() (ret []string)
- func (t *EmailTextbox) Deserialize(dec page.Decoder)
- func (t *EmailTextbox) Init(parent page.ControlI, id string)
- func (t *EmailTextbox) Serialize(e page.Encoder)
- func (t *EmailTextbox) SetMaxItemCount(max int) EmailI
- func (t *EmailTextbox) UpdateFormValues(ctx context.Context)
- func (t *EmailTextbox) Validate(ctx context.Context) bool
- type EmailTextboxCreator
- type FloatI
- type FloatLimit
- type FloatTextbox
- func (t *FloatTextbox) Float32() float32
- func (t *FloatTextbox) Float64() float64
- func (t *FloatTextbox) Init(parent page.ControlI, id string)
- func (t *FloatTextbox) SetFloat32(v float32) *FloatTextbox
- func (t *FloatTextbox) SetFloat64(v float64) *FloatTextbox
- func (t *FloatTextbox) SetMaxValue(maxValue float64, invalidMessage string) FloatI
- func (t *FloatTextbox) SetMinValue(minValue float64, invalidMessage string) FloatI
- func (t *FloatTextbox) SetValue(v interface{}) page.ControlI
- func (t *FloatTextbox) Value() interface{}
- type FloatTextboxCreator
- type FloatValidator
- type IntValidator
- type IntegerI
- type IntegerLimit
- type IntegerTextbox
- func (t *IntegerTextbox) Init(parent page.ControlI, id string)
- func (t *IntegerTextbox) Int() int
- func (t *IntegerTextbox) Int64() int64
- func (t *IntegerTextbox) SetInt(v int) IntegerI
- func (t *IntegerTextbox) SetMaxValue(maxValue int, invalidMessage string) IntegerI
- func (t *IntegerTextbox) SetMinValue(minValue int, invalidMessage string) IntegerI
- func (t *IntegerTextbox) SetValue(v interface{}) page.ControlI
- func (t *IntegerTextbox) Value() interface{}
- type IntegerTextboxCreator
- type MaxFloatValidator
- type MaxIntValidator
- type MaxLengthValidator
- type MinFloatValidator
- type MinIntValidator
- type MinLengthValidator
- type PasswordI
- type PasswordTextbox
- type PasswordTextboxCreator
- type PhoneI
- type PhoneTextbox
- type PhoneTextboxCreator
- type Textbox
- func (t *Textbox) Deserialize(d page.Decoder)
- func (t *Textbox) DrawInnerHtml(_ context.Context, w io.Writer)
- func (t *Textbox) DrawingAttributes(ctx context.Context) html5tag.Attributes
- func (t *Textbox) Init(parent page.ControlI, id string)
- func (t *Textbox) MarshalState(m page.SavedState)
- func (t *Textbox) MaxLength() int
- func (t *Textbox) MinLength() int
- func (t *Textbox) Placeholder() string
- func (t *Textbox) ResetValidators()
- func (t *Textbox) Sanitize(s string) string
- func (t *Textbox) Serialize(e page.Encoder)
- func (t *Textbox) SetColumnCount(columns int) TextboxI
- func (t *Textbox) SetMaxLength(len int) *MaxLengthValidator
- func (t *Textbox) SetMinLength(len int) *MinLengthValidator
- func (t *Textbox) SetPlaceholder(s string) TextboxI
- func (t *Textbox) SetReadOnly(r bool) TextboxI
- func (t *Textbox) SetRowCount(rows int) TextboxI
- func (t *Textbox) SetText(s string) page.ControlI
- func (t *Textbox) SetType(typ string) TextboxI
- func (t *Textbox) SetValue(v interface{}) page.ControlI
- func (t *Textbox) Text() string
- func (t *Textbox) UnmarshalState(m page.SavedState)
- func (t *Textbox) UpdateFormValues(ctx context.Context)
- func (t *Textbox) Validate(ctx context.Context) bool
- func (t *Textbox) ValidateWith(v Validater)
- func (t *Textbox) Value() interface{}
- type TextboxCreator
- type TextboxI
- type Validater
Constants ¶
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 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.
type DateValidator ¶
type DateValidator struct {
Message string
}
DateValidator specifies the message to show when the date is not validated.
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) 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
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.
type FloatLimit ¶
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.
type FloatValidator ¶
type FloatValidator struct {
Message string
}
type IntValidator ¶
type IntValidator struct {
Message string
}
type IntegerLimit ¶
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) 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.
type MaxFloatValidator ¶
type MaxIntValidator ¶
type MaxLengthValidator ¶
MaxLengthValidator is a Validater to test that the user did not enter too many characters.
type MinFloatValidator ¶
type MinIntValidator ¶
type MinLengthValidator ¶
MinLengthValidator is a validator that checks that the user has entered a minimum length. It is set up automatically by calling SetMinValue.
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.
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.
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.
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 ¶
GetTextbox is a convenience method to return the control with the given id from the page.
func NewTextbox ¶
NewTextbox creates a new GoRADD Textbox control.
func (*Textbox) Deserialize ¶
Deserialize is used by the pagestate serializer.
func (*Textbox) DrawInnerHtml ¶
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) MarshalState ¶
func (t *Textbox) MarshalState(m page.SavedState)
MarshalState is an internal function to save the state of the control
func (*Textbox) Placeholder ¶
Placeholder returns the value of the placeholder.
func (*Textbox) ResetValidators ¶
func (t *Textbox) ResetValidators()
ResetValidators removes all validators
func (*Textbox) Sanitize ¶
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 ¶
Serialize is used by the framework to serialize the textbox into the pagestate.
func (*Textbox) SetColumnCount ¶
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 ¶
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 ¶
SetReadOnly will disable editing by setting a browser attribute.
func (*Textbox) SetRowCount ¶
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) SetType ¶
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 ¶
SetValue sets the text in the textbox. This satisfies the Valuer interface.
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 ¶
UpdateFormValues is used by the framework to cause the control to retrieve its values from the form
func (*Textbox) Validate ¶
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 ¶
ValidateWith adds a Validater to the validator list.
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.
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.
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.