button

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package button includes button and button-like controls that are clickable, including things that toggle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UploadEvent added in v0.27.2

func UploadEvent() *event.Event

UploadEvent triggers when an upload has been completed. Put an action on this to read the FileHeaders and then copy the uploaded files.

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

func GetButton(c page.ControlI, id string) *Button

GetButton is a convenience method to return the button with the given id from the page.

func NewButton

func NewButton(parent page.ControlI, id string) *Button

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

func (b *Button) Init(self any, parent page.ControlI, id string)

Init is called by subclasses of Button to initialize the button control structure.

func (*Button) On

func (b *Button) On(e *event.Event, action action.ActionI) page.ControlI

On causes the given actions to execute when the given event is triggered.

func (*Button) OnClick

func (b *Button) OnClick(action action.ActionI) ButtonI

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

func (b *Button) OnSubmit(action action.ActionI) ButtonI

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

func (b *Button) SetIsPrimary(s bool) ButtonI

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.

func (*Button) SetLabel

func (b *Button) SetLabel(label string) ButtonI

SetLabel is an alias for SetText on buttons. Standard buttons do not normally have separate labels. Subclasses can redefine this if they use separate labels.

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

func (ButtonCreator) Create

func (c ButtonCreator) 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 (ButtonCreator) Init

func (c ButtonCreator) Init(ctx context.Context, ctrl ButtonI)

Init is called by implementations of Buttons to initialize a control with the creator.

type ButtonI

type ButtonI interface {
	page.ControlI
	SetLabel(label string) ButtonI
	OnSubmit(action action.ActionI) ButtonI
	OnClick(action action.ActionI) ButtonI
	SetIsPrimary(bool) ButtonI
}

type Checkbox

type Checkbox struct {
	CheckboxBase
}

Checkbox is a basic html checkbox input form control.

func GetCheckbox

func GetCheckbox(c page.ControlI, id string) *Checkbox

GetCheckbox is a convenience method to return the checkbox with the given id from the page.

func NewCheckbox

func NewCheckbox(parent page.ControlI, id string) *Checkbox

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

func (c *Checkbox) UpdateFormValues(ctx context.Context)

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(self any, 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
	// OnChange is an action to take when the user checks or unchecks the control.
	OnChange action.ActionI

	page.ControlOptions
}

func (CheckboxCreator) Create

func (c CheckboxCreator) 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.

type CheckboxI

type CheckboxI interface {
	page.ControlI
	GetDrawingLabelAttributes() html5tag.Attributes
}

CheckboxI is the interface for all checkbox-like objects.

type FileInfo added in v0.27.2

type FileInfo struct {
	Name        string `json:"name"`
	LasModified int    `json:"lastModified"`
	Size        int    `json:"size"`
	Type        string `json:"type"`
}

FileInfo is the information regarding each file selected. Call FileSelect.FileInfo to retrieve the information.

type FileSelect added in v0.27.2

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

FileSelect is a standard html file select button.

By default, it will only accept single file. Call SetMultiple to allow multiple selections, and SetAccept to control what types of files can be selected based on the file suffixes.

To get the list of files that have been selected, call FileInfo. However, to get to the files that are being uploaded, you must do one of the following:

  • create an Do action on the UploadEvent event, and then call the Upload function, or
  • create a Server action on a submit button.

In your DoAction handler, call FileHeaders on the FileSelect to retrieve the file headers. You then must immediately call Open on each FileHeader to retrieve the information in each file that was uploaded, since Go will delete the files after the event is finished processing.

If you would like to trigger an UploadEvent as soon as files are selected, call SetUploadOnChange.

If your application is running behind a web server like apache or nginx, you probably will need to set the maximum upload file size in that software.

func GetFileSelect added in v0.27.2

func GetFileSelect(c page.ControlI, id string) *FileSelect

GetFileSelect is a convenience method to return the button with the given id from the page.

func NewFileSelect added in v0.27.2

func NewFileSelect(parent page.ControlI, id string) *FileSelect

NewFileSelect creates a new file select button.

func (*FileSelect) Deserialize added in v0.27.2

func (b *FileSelect) Deserialize(d page.Decoder)

Deserialize is called by the framework during page state serialization.

func (*FileSelect) DrawingAttributes added in v0.27.2

func (b *FileSelect) DrawingAttributes(ctx context.Context) html5tag.Attributes

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

func (*FileSelect) FileHeaders added in v0.27.2

func (b *FileSelect) FileHeaders() []*multipart.FileHeader

FileHeaders returns the file headers for the most recently submitted files. The files pointed to by the file headers are only valid when responding to the UploadEvent() event. After that, the files they point to will be deleted.

func (*FileSelect) FileInfos added in v0.27.2

func (b *FileSelect) FileInfos() []FileInfo

FileInfos returns the file information about each file selected. FileInfo information is not available for Server events.

func (*FileSelect) Init added in v0.27.2

func (b *FileSelect) Init(self any, parent page.ControlI, id string)

Init is called by subclasses of Button to initialize the button control structure.

func (*FileSelect) Serialize added in v0.27.2

func (b *FileSelect) Serialize(e page.Encoder)

Serialize is called by the framework during pagestate serialization.

func (*FileSelect) SetAccept added in v0.27.2

func (b *FileSelect) SetAccept(a string)

SetAccept is a comma separated list of file endings to filter what is visible in the file selection dialog. i.e. ".jqg, .jpeg"

func (*FileSelect) SetMultiple added in v0.27.2

func (b *FileSelect) SetMultiple(m bool)

SetMultiple controls whether the button allows multiple file selections.

func (*FileSelect) SetUploadOnChange added in v0.27.2

func (b *FileSelect) SetUploadOnChange(up bool)

SetUploadOnChange will set whether the onchange event will immediately trigger the upload process. For the upload to happen, you must create an action on the UploadEvent.

func (*FileSelect) UpdateFormValues added in v0.27.2

func (b *FileSelect) UpdateFormValues(ctx context.Context)

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

func (*FileSelect) Upload added in v0.27.2

func (b *FileSelect) Upload()

Upload will trigger the upload process. Create an action on the UploadEvent() event to respond once the files are uploaded.

type FileSelectCreator added in v0.27.2

type FileSelectCreator struct {
	// ID is the control id
	ID string
	// Multiple controls whether multiple files can be selected
	Multiple bool
	// Accept is a list of command separated file endings that will filter
	// the visible files. i.e. ".jpg, .jpeg"
	Accept string
	// OnChange is an action to take when a file has been selected.
	OnChange action.ActionI
	// UploadOnChange indicates that the upload process should proceed immediately when a file is selected.
	UploadOnChange bool
	// OnUpload is an action to take after the Upload() command has completed. Respond to this action by calling
	// FileHeaders() to get the FileHeaders of the uploaded files and then copying those files to a more permanent place.
	OnUpload action.ActionI

	// ControlOptions are additional options that are common to all controls.
	page.ControlOptions
}

FileSelectCreator is the initialization structure for declarative creation of file selection buttons

func (FileSelectCreator) Create added in v0.27.2

func (c FileSelectCreator) 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 (FileSelectCreator) Init added in v0.27.2

func (c FileSelectCreator) Init(ctx context.Context, ctrl FileSelectI)

Init is called by implementations of controls to initialize a control with the creator.

type FileSelectI added in v0.27.2

type FileSelectI interface {
	page.ControlI
	SetUploadOnChange(bool)
	SetMultiple(bool)
	SetAccept(string)
}

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
}

func (RadioButtonCreator) Create

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

type RadioButtonI

type RadioButtonI interface {
	CheckboxI
}

Jump to

Keyboard shortcuts

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