event

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 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.

e := Click().Delay(200).Blocking()
btn := NewButton().On(e, 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 = "grdlgclosed"

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 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 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 action2.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 Backspace

func Backspace() *Event

Backspace 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 of 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

func CheckboxColumnClick

func CheckboxColumnClick() *Event

CheckboxColumnClick retuns 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 DownArrow

func DownArrow() *Event

DownArrow 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

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 RowSelected

func RowSelected() *Event

RowSelected is an event that indicates a row was selected on a SelectTable.

func Select

func Select() *Event

func TabKey

func TabKey() *Event

TabKey is a keydown event for the tab key.

func TableSort

func TableSort() *Event

TableSort is a custom event for responding to a table sort event

func TimerExpired

func TimerExpired() *Event

TimerExpired is used in conjunction with a JsTimer control to detect the expiration of the timer

func UpArrow

func UpArrow() *Event

UpArrow is a keydown event for the up arrow.

func (*Event) ActionValue added in v0.21.0

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

ActionValue is a value that will be returned to the actions that will be process 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 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) GetActionValue added in v0.21.0

func (e *Event) GetActionValue() interface{}

GetActionValue returns the value associated with the action of the event.

func (*Event) GetCallbackAction added in v0.21.0

func (e *Event) GetCallbackAction() action2.FrameworkCallbackActionI

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

func (*Event) GetValidationOverride added in v0.21.0

func (e *Event) GetValidationOverride() ValidationType

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

func (*Event) GobDecode added in v0.21.0

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

func (*Event) GobEncode added in v0.21.0

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

func (*Event) HasCallbackAction added in v0.21.0

func (e *Event) HasCallbackAction() bool

HasCallbackAction returns true if at least one of the event's actions is a callback action.

func (*Event) HasServerAction added in v0.21.0

func (e *Event) HasServerAction() bool

HasServerAction returns true if at least one of the event's actions is a server action.

func (*Event) IsPrivate added in v0.21.0

func (e *Event) IsPrivate() bool

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

func (*Event) Name added in v0.21.0

func (e *Event) Name() string

Name returns the name of the javascript event being triggered.

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) PreventingDefault added in v0.21.0

func (e *Event) PreventingDefault() *Event

PreventingDefault 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
)

Jump to

Keyboard shortcuts

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