event

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package event contains functions that specify various kinds of javascript events that GoRADD controls respond to.

Create an event by using one of the predefined event creation functions like Click, or call NewEvent to create an event that responds to any named javascript event. If needed, add additional requirements for the event using the builder pattern functions like Event.Delay, Event.Selector and Event.Condition.

For example, the code below will create an event that waits for clicks on the button, but debounces the clicks and also prevents all other actions from happening while waiting for the event to fire. This would be typically useful in a submit button where you want to prevent multiple submissions of the same button.

btn := NewButton().On(event.Click().Delay(200).Blocking(), action.Redirect("/mypage"))

Index

Constants

View Source
const (
	CellClickDefault     = `{"row": event.goradd.match.parentElement.rowIndex, "col": event.goradd.match.cellIndex}`
	CellClickRowIndex    = `event.goradd.match.parentElement.rowIndex`
	CellClickColumnIndex = `event.goradd.match.cellIndex`
	CellClickCellId      = `event.goradd.match.id`
	CellClickRowId       = `event.goradd.match.parentElement.id`
	CellClickRowValue    = `g$(event.goradd.match).closest("tr").data("value")`
	CellClickColId       = `g$(event.goradd.match).columnId()`
)
View Source
const ClickEvent = "click"
View Source
const DialogButtonEvent = "gr-dlgbtn"
View Source
const DialogClosedEvent = "gr-dlgclosed"

Variables

This section is empty.

Functions

func CellDataActionValue added in v0.2.0

func CellDataActionValue(key string) javascript.JavaScripter

CellDataActionValue sets the ActionValue to javascript that will return the data value of the row clicked on. If you are going to use this, call it immediately after you call CellClick, and before any other calls on the event. For example:

e := event.CellClick().ActionValue(event.CellDataActionValue("cellVal")).Delay(100)

func GetActionValue added in v0.21.1

func GetActionValue(e *Event) interface{}

GetActionValue returns the event value associated with the actions resulting from the event.

func GetCallbackAction added in v0.21.1

func GetCallbackAction(e *Event) action.CallbackActionI

GetCallbackAction will return the action associated with the event if it is a callback action. Otherwise, it will return nil.

func IsPrivate added in v0.21.1

func IsPrivate(e *Event) bool

IsPrivate returns whether this is an event private to the control or one created from outside the control.

func Name added in v0.21.1

func Name(e *Event) string

Name returns the name of the javascript event being triggered.

func RenderActions added in v0.21.0

func RenderActions(e *Event, control renderer, eventID EventID) string

RenderActions is used internally by the framework to render the javascript associated with the event and connected actions. You should not normally need to call this function.

func RowDataActionValue added in v0.2.0

func RowDataActionValue(key string) javascript.JavaScripter

RowDataActionValue returns code to use in the ActionValue to return the data value of the row clicked on. The code can be used directly, or in a map or array. For example:

e := event.CellClick().ActionValue(event.RowDataActionValue("rowVal")).Delay(100)

func SetEventItems added in v0.21.0

func SetEventItems(e *Event, action action.ActionI, eventId EventID)

SetEventItems is used internally by the framework to set up an event. You should not normally need to call this function.

Types

type CheckboxColumnActionValues

type CheckboxColumnActionValues struct {
	Row     int    `json:"row"`
	Column  int    `json:"col"`
	Checked bool   `json:"checked"`
	Id      string `json:"id"`
}

CheckboxColumnActionValues can be used to get the values out of the Event.

type Event

type Event struct {
	// contains filtered or unexported fields
}

Event represents a javascript event that triggers an action. Create it with a call to NewEvent(), or one of the predefined events in the event package, like event.Click()

func BackspaceKey added in v0.22.0

func BackspaceKey() *Event

BackspaceKey is a keydown event for the backspace key.

func BeforeInput added in v0.21.0

func BeforeInput() *Event

BeforeInput responds to the javascript "beforeinput" event. This event is fired before a control is changed by text edits.

func Blur

func Blur() *Event

Blur returns an event that responds to the javascript "blur" event. This is typically fired when a control loses focus, though there are bugs in some browsers that prevent the blur event when the control loses focus when the entire browser is placed in the background.

func CellClick

func CellClick() *Event

CellClick returns an event to detect clicking on a table cell. Lots of things can be determined using this event by changing the return values. When this event fires, the javascript environment will have the following local variables defined:

  • this: The object on to which the event listener was attached.
  • event: The event object for the click.
  • event.target - the html object clicked in. If your table cell had other objects in it, this will return the object clicked inside the cell. This could be important, for example, if you had form objects inside the cell, and you wanted to behave differently if a form object was clicked on, verses clicking outside the form object.
  • event.goradd.match: This will be the cell object clicked on, even if an item inside the cell was clicked.

Here are some examples of return params you can specify to return data to your action handler:

event.goradd.match.id - the cell id
event.goradd.match.tagName - the tag for the cell (either th or td)
event.goradd.match.cellIndex - the table index that was clicked on, starting on the left with table zero
g$(event.goradd.match).data('value') - the "data-value" attribute of the cell (if you specify one). Use this formula for any kind of "data-" attribute.
g$(event.goradd.match).parent() - the javascript row object
event.goradd.match.parentElement - the html row object
event.goradd.match.parentElement.rowIndex - the index of the row clicked, starting with zero at the top (including any header rows).
event.goradd.match.parentElement.id the id of the row clicked on
g$(event.goradd.match).parent().data("value") - the "data-value" attribute of the row.
g$(event.goradd.match).columnId() - the id of the column clicked in

You can put your items in a javascript array, and an array will be returned as the strParameter in the action. Or you can put it in a javascript object, and a named array(hash) will be returned.

By default, the cell click does not bubble. Add Bubbles() to the event to get the click to bubble up from sub objects.

func Change

func Change() *Event

Change triggers on the javascript change event. The change event triggers after a change has been recorded on a control. For text boxes, this occurs after focus leaves the text box. Other controls, like select controls, change immediately when a new item is selected.

func CheckboxColumnClick

func CheckboxColumnClick() *Event

CheckboxColumnClick returns an event that will detect a click on a checkbox table in a table, and set up the return parameters to return:

row: the index of the clicked row
col: the index of the clicked table
checked: the checked state of the checkbox after the click is processed
id: the id of the cell clicked

func Click

func Click() *Event

Click is an event that responds to the javascript "click" event.

func ContextMenu

func ContextMenu() *Event

ContextMenu returns an event that responds to a context menu click, which is typically done by right-clicking on a two mouse button, option-clicking or two-finger clicking on a Mac, or tap and hold on a touch device.

func DialogButton

func DialogButton() *Event

DialogButton returns an event that detects clicking on a dialog's button.

func DialogClosed

func DialogClosed() *Event

DialogClosed indicates that a dialog has closed. This is a good time to do any required cleanup.

func DoubleClick

func DoubleClick() *Event

DoubleClick is an event that responds to the javascript "dblclick" event.

func DownArrowKey added in v0.22.0

func DownArrowKey() *Event

DownArrowKey is a keydown event for the down arrow.

func DragDrop

func DragDrop() *Event

DragDrop returns an event that responds to the javascript drop event

func EnterKey

func EnterKey() *Event

EnterKey is a keydown event for the enter key.

func EscapeKey

func EscapeKey() *Event

EscapeKey is a keydown event for the escape key.

func Focus

func Focus() *Event

Focus returns an event that responds to the javascript "focus" event. This event is triggered when a control receives the focus.

func FocusIn

func FocusIn() *Event

FocusIn returns an event that responds to the javascript "focusin" event. This is fired when a control, or any of its nested controls, gains focus. In other words, the event bubbles.

func FocusOut

func FocusOut() *Event

FocusOut returns an event that responds to the javascript "focusout" event. This is fired when a control, or any of its nested controls, loses focus. In other words, the event bubbles.

func HeaderCellClick added in v0.12.0

func HeaderCellClick() *Event

HeaderCellClick responds to clicks on header cells (th)

func Input

func Input() *Event

Input triggers on the input event. The input event happens when text box type controls have been changed at all. This is the event you want to watch if you want to know when a user has typed in a text box, or pressed backspace, or cut or pasted into the text box.

func KeyDown

func KeyDown() *Event

KeyDown responds to the javascript "keydown" event.

func KeyPress

func KeyPress() *Event

KeyPress responds to the javascript "keypress" event. Deprecated: this is deprecated by the web standards. Use KeyDown or BeforeInput instead.

func KeyUp

func KeyUp() *Event

KeyUp responds to the javascript "keyup" event.

func NewEvent added in v0.21.0

func NewEvent(name string) *Event

NewEvent creates an event that triggers on the given javascript event name. Use the builder pattern functions from *Event to add delays, conditions, etc.

func Select

func Select() *Event

Select triggers on the select event. The select event happens when text is selected in the control.

func TabKey

func TabKey() *Event

TabKey is a keydown event for the tab key.

func UpArrowKey added in v0.22.0

func UpArrowKey() *Event

UpArrowKey is a keydown event for the up arrow.

func (*Event) ActionValue added in v0.21.0

func (e *Event) ActionValue(r interface{}) *Event

ActionValue sets the event value in the actions triggered by this event. Specify a static value, or javascript objects that will gather data at the time the event fires. The event will appear in the Params as the EventValue. By default, this will be the value passed in to the javascript event as event data.

See on: and trigger: in goradd.js.

For example:

ActionValue(javascript.JsCode{"event.target.id"})

will cause the EventValue for the action to be the HTML id of the target object of the event.

func (*Event) Blocking added in v0.21.0

func (e *Event) Blocking() *Event

Blocking prevents other events from firing after this fires, but before it processes. If another event fires between the time when this event fires and when a response is received, it will be lost.

func (*Event) Bubbles added in v0.21.0

func (e *Event) Bubbles() *Event

Bubbles works with a Selector to allow events to come from a sub-control of the selected control. The event could be blocked by the sub-control if the sub-control issues a preventPropagation on the event.

func (*Event) Capture added in v0.21.0

func (e *Event) Capture() *Event

Capture works with a Selector to allow events to come from a sub-control of the selected control. The event never actually reaches the sub-control for processing, and instead is captured and handled by the selected control. This is generally used in special situations where you do not want to allow sub-controls to prevent bubbling.

func (*Event) Condition added in v0.21.0

func (e *Event) Condition(javascript string) *Event

Condition specifies a javascript condition to check before triggering the event. The given string should be javascript code that evaluates to a boolean value.

func (*Event) Delay added in v0.21.0

func (e *Event) Delay(delay int) *Event

Delay is the time in milliseconds to wait before triggering the actions.

During the delay time, if the event is repeated, the delay timer will restart and only one event will eventually be fired. For example, if you have a KeyDown event with a delay, and the user enters multiple keys during the delay time, only one keydown event will fire, and it will fire delay ms after the last keydown event was received.

func (*Event) EventValueTargetID added in v0.21.1

func (e *Event) EventValueTargetID() *Event

EventValueTargetID will set the event value of the resulting action to the HTML id of the target of the event.

func (*Event) GobDecode added in v0.21.0

func (e *Event) GobDecode(data []byte) (err error)

GobDecode is called by the framework to binary decode the event.

func (*Event) GobEncode added in v0.21.0

func (e *Event) GobEncode() (data []byte, err error)

GobEncode is called by the framework to binary encode the event.

func (*Event) PreventBubbling added in v0.21.0

func (e *Event) PreventBubbling() *Event

PreventBubbling causes the event to not bubble to enclosing objects.

func (*Event) PreventDefault added in v0.22.0

func (e *Event) PreventDefault() *Event

PreventDefault causes the event not to do the default action.

func (*Event) Private added in v0.21.0

func (e *Event) Private() *Event

Private makes the event private to the control and not removable. This should generally only be used by control implementations to add events that are required by the control and that should not be removed by Off()

func (*Event) Selector added in v0.21.0

func (e *Event) Selector(s string) *Event

Selector specifies a CSS filter that is used to check for bubbled events. This allows the event to be fired from child controls. By default, the event will not come from sub-controls of the specified child controls. Use Bubbles or Capture to change that.

func (*Event) String added in v0.21.0

func (e *Event) String() string

String returns a debug string listing the contents of the event.

func (*Event) Terminating added in v0.21.0

func (e *Event) Terminating() *Event

Terminating prevents the event from bubbling or doing the default action. It is essentially a combination of calling PreventDefault and StopPropagation.

func (*Event) Validate added in v0.21.0

func (e *Event) Validate(v ValidationType) *Event

Validate overrides the controls validation setting just for this event.

func (*Event) ValidationTargets added in v0.21.0

func (e *Event) ValidationTargets(targets ...string) *Event

ValidationTargets overrides the control's validation targets just for this event.

type EventID added in v0.21.0

type EventID uint16

EventID is used internally by the framework to set a unique id used to specify which event is triggering.

type ValidationType added in v0.21.0

type ValidationType int

ValidationType is used by active controls, like buttons, to determine what other items on the form will get validated when the button is pressed. You can set the ValidationType for a control, but you can also set it for individual events and override the control's validation setting.

const (
	// ValidateDefault is used by events to indicate they are not overriding a control validation. You should not need to use this.
	ValidateDefault ValidationType = iota
	// ValidateNone indicates the control will not validate the form
	ValidateNone
	// ValidateForm is the default validation for buttons, and indicates the entire form and all controls will validate.
	ValidateForm
	// ValidateSiblingsAndChildren will validate the current control, and all siblings of the control and all
	// children of the siblings and current control.
	ValidateSiblingsAndChildren
	// ValidateSiblingsOnly will validate only the siblings of the current control, but not any child controls.
	ValidateSiblingsOnly
	// ValidateChildrenOnly will validate only the children of the current control.
	ValidateChildrenOnly
	// ValidateContainer will use the validation setting of a parent control with ValidateSiblingsAndChildren, ValidateSiblingsOnly,
	// ValidateChildrenOnly, or ValidateTargetsOnly as the stopping point for validation.
	ValidateContainer
	// ValidateTargetsOnly will only validate the specified targets
	ValidateTargetsOnly
)

func GetValidationOverride added in v0.21.1

func GetValidationOverride(e *Event) ValidationType

GetValidationOverride returns the validation type of the event that will override the control's validation type.

Jump to

Keyboard shortcuts

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