Documentation ¶
Overview ¶
Package button includes button and button-like controls that are clickable, including things that toggle.
Index ¶
- type Button
- func (b *Button) DrawingAttributes(ctx context.Context) html5tag.Attributes
- func (b *Button) Init(parent page.ControlI, id string)
- func (b *Button) On(e *event.Event, action action.ActionI) page.ControlI
- func (b *Button) OnClick(action action.ActionI) ButtonI
- func (b *Button) OnSubmit(action action.ActionI) ButtonI
- func (b *Button) SetIsPrimary(s bool) ButtonI
- func (b *Button) SetLabel(label string) ButtonI
- type ButtonCreator
- type ButtonI
- type Checkbox
- type CheckboxBase
- func (c *CheckboxBase) Checked() bool
- func (c *CheckboxBase) Deserialize(d page.Decoder)
- func (c *CheckboxBase) DrawTag(ctx context.Context, w io.Writer)
- func (c *CheckboxBase) DrawingAttributes(ctx context.Context) html5tag.Attributes
- func (c *CheckboxBase) GetDrawingLabelAttributes() html5tag.Attributes
- func (c *CheckboxBase) Init(parent page.ControlI, id string)
- func (c *CheckboxBase) LabelAttributes() html5tag.Attributes
- func (c *CheckboxBase) MarshalState(m page.SavedState)
- func (c *CheckboxBase) Serialize(e page.Encoder)
- func (c *CheckboxBase) SetChecked(v bool) CheckboxI
- func (c *CheckboxBase) SetCheckedNoRefresh(v interface{})
- func (c *CheckboxBase) SetLabelDrawingMode(m html5tag.LabelDrawingMode)
- func (c *CheckboxBase) SetValue(v interface{}) CheckboxI
- func (c *CheckboxBase) TextIsLabel() bool
- func (c *CheckboxBase) UnmarshalState(m page.SavedState)
- func (c *CheckboxBase) UpdateCheckboxFormValues(ctx context.Context)
- func (c *CheckboxBase) UpdateRadioFormValues(ctx context.Context, group string)
- func (c *CheckboxBase) Value() interface{}
- type CheckboxCreator
- type CheckboxI
- type RadioButton
- func (l *RadioButton) Deserialize(dec page.Decoder)
- func (c *RadioButton) DrawingAttributes(ctx context.Context) html5tag.Attributes
- func (c *RadioButton) Group() string
- func (l *RadioButton) Serialize(e page.Encoder)
- func (c *RadioButton) SetChecked(v bool) RadioButtonI
- func (c *RadioButton) SetGroup(g string) RadioButtonI
- func (c *RadioButton) UpdateFormValues(ctx context.Context)
- type RadioButtonCreator
- type RadioButtonI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Button ¶
type Button struct {
page.ControlBase
}
Button is a standard html form button. It corresponds to a <button> tag in html.
By default, we set the "type" attribute of the button to "button". This will prevent the button from submitting the form when the user presses the return key. To choose which button will submit on a return, call SetIsPrimary() or set the "type" attribute to "submit".
If multiple "submit" buttons are on the page, the default behavior will occur if there are text boxes on the form, and pressing enter will submit the FIRST button in the form as encountered in the HTML. Using CSS to alter the placement of the buttons (using float for instance), will not change which button the browser considers to be the first.
If you want the button to display an image, create an Image control as a child of the button.
func GetButton ¶
GetButton is a convenience method to return the button with the given id from the page.
func NewButton ¶
NewButton creates a new standard HTML button.
Detect clicks by assigning an action to the OnClick method.
func (*Button) DrawingAttributes ¶
func (b *Button) DrawingAttributes(ctx context.Context) html5tag.Attributes
DrawingAttributes retrieves the tag's attributes at draw time. You should not normally need to call this, and the attributes are disposed of after drawing, so they are essentially read-only.
func (*Button) Init ¶
Init is called by subclasses of Button to initialize the button control structure.
func (*Button) OnClick ¶
OnClick is a shortcut for adding a click event handler.
If your handler causes a new page to load, you should consider using OnSubmit instead.
func (*Button) OnSubmit ¶
OnSubmit is a shortcut for adding a click event handler that is particular to buttons and button like objects. It debounces the click, so that all other events are lost until this event processes. It should generally be used for operations that will redirect to a different page. If coupling this with an ajax response, you should probably also make the response priority PriorityFinal.
func (*Button) SetIsPrimary ¶
SetIsPrimary will set this button to be the default button on the form, which is the button clicked when the user presses a return. Some browsers only respond to this when there is a textbox on the screen.
type ButtonCreator ¶
type ButtonCreator struct { // ID is the control id ID string // Text is the text displayed in the button Text string // Set IsPrimary to true to make this the default button on the page IsPrimary bool // OnSubmit is the action to take when the button is submitted. Use this specifically // for buttons that move to other pages or processes transactions, as it debounces the button // and waits until all other actions complete OnSubmit action.ActionI // OnClick is an action to take when the button is pressed. Do not specify both // a OnClick and OnSubmit. OnClick action.ActionI // ValidationType controls how the page will be validating when the button is clicked. ValidationType event.ValidationType // ControlOptions are additional options that are common to all controls. page.ControlOptions }
ButtonCreator is the initialization structure for declarative creation of buttons
type Checkbox ¶
type Checkbox struct {
CheckboxBase
}
Checkbox is a basic html checkbox input form control.
func GetCheckbox ¶
GetCheckbox is a convenience method to return the checkbox with the given id from the page.
func NewCheckbox ¶
NewCheckbox creates a new checkbox control.
func (*Checkbox) DrawingAttributes ¶
func (c *Checkbox) DrawingAttributes(ctx context.Context) html5tag.Attributes
DrawingAttributes is called by the framework to set the temporary attributes that the control needs. Checkboxes set the grctl, name, type and value attributes automatically. You do not normally need to call this function.
func (*Checkbox) UpdateFormValues ¶
UpdateFormValues is an internal call that lets us reflect the value of the checkbox on the form. You do not normally need to call this function.
type CheckboxBase ¶
type CheckboxBase struct { page.ControlBase // LabelMode describes where to place the label associating the text with the checkbox. The default is the // global page.DefaultCheckboxLabelDrawingMode, and you would normally set that instead so that all your checkboxes draw // the same way. LabelMode html5tag.LabelDrawingMode // contains filtered or unexported fields }
CheckboxBase is a base class for checkbox-like objects, including html checkboxes and radio buttons.
func (*CheckboxBase) Checked ¶
func (c *CheckboxBase) Checked() bool
Checked returns true if the checkbox is checked.
func (*CheckboxBase) Deserialize ¶
func (c *CheckboxBase) Deserialize(d page.Decoder)
Deserialize is called by the framework during page state serialization.
func (*CheckboxBase) DrawTag ¶
func (c *CheckboxBase) DrawTag(ctx context.Context, w io.Writer)
DrawTag draws the checkbox tag. This can be quite tricky. Some CSS frameworks are very particular about how checkboxes get associated with labels. The Text value of the control will become the text directly associated with the checkbox, while the Label value is only shown when drawing a checkbox with a wrapper.
func (*CheckboxBase) DrawingAttributes ¶
func (c *CheckboxBase) DrawingAttributes(ctx context.Context) html5tag.Attributes
DrawingAttributes retrieves the tag's attributes at draw time. You should not normally need to call this, and the attributes are disposed of after drawing, so they are essentially read-only.
func (*CheckboxBase) GetDrawingLabelAttributes ¶
func (c *CheckboxBase) GetDrawingLabelAttributes() html5tag.Attributes
GetDrawingLabelAttributes is called by the framework to temporarily set the attributes of the label associated with the checkbox.
func (*CheckboxBase) Init ¶
func (c *CheckboxBase) Init(parent page.ControlI, id string)
Init initializes a checkbox base class. It is called by checkbox implementations.
func (*CheckboxBase) LabelAttributes ¶
func (c *CheckboxBase) LabelAttributes() html5tag.Attributes
LabelAttributes returns a pointer to the input label attributes. Feel free to set the attributes directly on the returned object. The input label attributes are the attributes for the label tag that associates the Text with the checkbox. This is specific to checkbox style controls and is not the same as the label tag that appears when using a FormFieldWrapper wrapper. After setting attributes, be sure to call Refresh on the control if you do this during an Ajax response.
func (*CheckboxBase) MarshalState ¶
func (c *CheckboxBase) MarshalState(m page.SavedState)
MarshalState is called by the framework to save the state of the checkbox between form views. Call SetState(true) to enable state saving.
func (*CheckboxBase) Serialize ¶
func (c *CheckboxBase) Serialize(e page.Encoder)
Serialize is called by the framework during pagestate serialization.
func (*CheckboxBase) SetChecked ¶
func (c *CheckboxBase) SetChecked(v bool) CheckboxI
SetChecked sets the value of the checkbox. Returns itself for chaining.
func (*CheckboxBase) SetCheckedNoRefresh ¶
func (c *CheckboxBase) SetCheckedNoRefresh(v interface{})
SetCheckedNoRefresh is used internally to update values without causing a refresh loop.
func (*CheckboxBase) SetLabelDrawingMode ¶
func (c *CheckboxBase) SetLabelDrawingMode(m html5tag.LabelDrawingMode)
SetLabelDrawingMode determines how the label is drawn for the checkbox.
func (*CheckboxBase) SetValue ¶
func (c *CheckboxBase) SetValue(v interface{}) CheckboxI
SetValue sets the checked status of checkbox. The given value can be:
For True "1", "true", "TRUE", "on", "ON", 1(int), true(bool)
For False "0", "false", "FALSE", "off, "OFF", ""(empty string), 0(int), false(bool)
Other values will cause a panic.
func (*CheckboxBase) TextIsLabel ¶
func (c *CheckboxBase) TextIsLabel() bool
TextIsLabel is called by the framework to determine that the Text of the control is used in a label tag. You do not normally need to call this unless you are creating the template for a custom control.
func (*CheckboxBase) UnmarshalState ¶
func (c *CheckboxBase) UnmarshalState(m page.SavedState)
UnmarshalState restores the state of the checkbox if coming back to a form in the same session.
func (*CheckboxBase) UpdateCheckboxFormValues ¶
func (c *CheckboxBase) UpdateCheckboxFormValues(ctx context.Context)
UpdateCheckboxFormValues is used by subclasses of CheckboxBase to update their internal state if they are a checkbox type of control.
func (*CheckboxBase) UpdateRadioFormValues ¶
func (c *CheckboxBase) UpdateRadioFormValues(ctx context.Context, group string)
UpdateRadioFormValues is used by subclasses of CheckboxBase to update their internal state if they are a radioButton type of control.
func (*CheckboxBase) Value ¶
func (c *CheckboxBase) Value() interface{}
Value returns the boolean checked status of the checkbox.
type CheckboxCreator ¶
type CheckboxCreator struct { // ID is the id of the control ID string // Text is the text of the label displayed right next to the checkbox. Text string // Checked will initialize the checkbox in its checked state. Checked bool // LabelMode specifies how the label is drawn with the checkbox. LabelMode html5tag.LabelDrawingMode // LabelAttributes are additional attributes placed on the label tag. LabelAttributes html5tag.Attributes // SaveState will save the value of the checkbox and restore it when the page is reentered. SaveState bool page.ControlOptions }
type CheckboxI ¶
type CheckboxI interface { page.ControlI GetDrawingLabelAttributes() html5tag.Attributes }
CheckboxI is the interface for all checkbox-like objects.
type RadioButton ¶
type RadioButton struct { CheckboxBase // contains filtered or unexported fields }
RadioButton is a standard html radio button. You can optionally specify a group name for the radiobutton to belong to and the browser will make sure only one item in the group is selected.
func GetRadioButton ¶
func GetRadioButton(c page.ControlI, id string) *RadioButton
GetRadioButton is a convenience method to return the radio button with the given id from the page.
func NewRadioButton ¶
func NewRadioButton(parent page.ControlI, id string) *RadioButton
NewRadioButton creates a new radio button
func (*RadioButton) Deserialize ¶
func (l *RadioButton) Deserialize(dec page.Decoder)
func (*RadioButton) DrawingAttributes ¶
func (c *RadioButton) DrawingAttributes(ctx context.Context) html5tag.Attributes
DrawingAttributes is called by the framework to create temporary attributes for the input tag.
func (*RadioButton) Group ¶
func (c *RadioButton) Group() string
Group returns the name of the group that the control belongs to.
func (*RadioButton) Serialize ¶
func (l *RadioButton) Serialize(e page.Encoder)
func (*RadioButton) SetChecked ¶
func (c *RadioButton) SetChecked(v bool) RadioButtonI
SetChecked will set the checked status of this radio button to the given value.
func (*RadioButton) SetGroup ¶
func (c *RadioButton) SetGroup(g string) RadioButtonI
SetGroup sets the name of the group that the control will belong to. Set all the radio buttons that represent a selection from a group to this same group name.
func (*RadioButton) UpdateFormValues ¶
func (c *RadioButton) UpdateFormValues(ctx context.Context)
UpdateFormValues is used by the framework to cause the control to retrieve its values from the form
type RadioButtonCreator ¶
type RadioButtonCreator struct { // ID is the id of the control ID string // Text is the text of the label displayed right next to the checkbox. Text string // Checked will initialize the checkbox in its checked state. Checked bool // LabelMode specifies how the label is drawn with the checkbox. LabelMode html5tag.LabelDrawingMode // LabelAttributes are additional attributes placed on the label tag. LabelAttributes html5tag.Attributes // SaveState will save the value of the checkbox and restore it when the page is reentered. SaveState bool // Group is the name of the group that the button belongs to Group string page.ControlOptions }
type RadioButtonI ¶
type RadioButtonI interface { CheckboxI }