new Button(id, text, callbackObject, callback)
A button. Always takes up the whole width of the container.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | ID of this input. You can select this object using this ID. |
text |
string | Text for the button. Pass locale property to localize the text. |
callbackObject |
Object | L.ALS.Serializable | Just pass "this". If you plan to use serialization, this object MUST be instance of L.ALS.Serializable. |
callback |
string | Name of a method of callbackObject that will be called when button will be pressed. |
Extends
Members
-
<protected> constructorArguments :Array.<any>
-
Contains arguments passed to this constructor
Type:
- Array.<any>
- Inherited From:
-
<protected> container :HTMLDivElement
-
Container of this widget
Type:
- HTMLDivElement
- Inherited From:
-
<protected> containerForRevertButton :Element
-
Container to place revert button to. Used by the settings.
Type:
- Element
- Inherited From:
-
<protected, readonly> customContainerClassName
-
Custom classname for a widget container.
- Inherited From:
-
<protected, readonly> customWrapperClassName
-
Custom classname for an input wrapper. Alternative to setting classname at
L.ALS.Widgets.BaseWidget#createContainer
manually.- Inherited From:
- Overrides:
-
<readonly> id
-
This widget's ID
- Inherited From:
-
<protected> input :HTMLElement
-
Input element controlled by this widget
Type:
- HTMLElement
- Inherited From:
-
<protected> serializationIgnoreList :Array.<string>
-
Contains properties that won't be serialized. Append your properties at the constructor.
Type:
- Array.<string>
- Inherited From:
-
<readonly> undoable
-
Indicates whether this widget can revert back to its default value. If this widget is undoable, an undo button will be appended to it at settings window.
- Inherited From:
- Overrides:
-
wrapLabel
-
Indicates whether this widgets label should be wrapped when it's too wide. Wrapping might affect how your widget displays. Test it with both short labels and long labels.
- Inherited From:
Methods
-
callCallback()
-
Calls callback attached to this widget
Warning: Callback will be called only when widget will be added to the widgetable! Util that all calls will be paused.
- Inherited From:
Returns:
- Type
- VoidFunction
-
<protected> createContainer()
-
Creates container for this widget
- Inherited From:
Returns:
Container for this widget
- Type
- HTMLDivElement
-
<protected> createInput()
-
Creates input element. If you're creating different element, override createInputElement() instead of this.
- Inherited From:
Returns:
Input element
- Type
- HTMLElement
-
<protected> createInputElement()
-
Creates input element. You can also create non-input elements here.
Use it only to create input element. To add input element at
L.ALS.Widgets.BaseWidget#toHtmlElement
, useL.ALS.Widgets.BaseWidget#createInput
- Inherited From:
- Overrides:
Returns:
Input element
- Type
- HTMLElement
-
<protected> createLabel()
-
Creates label for this widget
- Inherited From:
Returns:
Label
- Type
- HTMLLabelElement
-
getButtonText()
-
Returns:
Button text
- Type
- string
-
getEnabled()
-
- Inherited From:
Returns:
True, if this widget is enabled. False otherwise.
- Type
- boolean
-
getLabelText()
-
- Inherited From:
Returns:
Text of the label of this widget or locale property (if set)
- Type
- string
-
getMobileIcon()
-
Returns:
Mobile icon of this button. If no mobile icon has been set, returns empty string.
- Type
- string
-
getObjectToSerializeTo(newObject, seenObjects)
-
Registers this object for serialization and deserialization. Returns an object to serialize custom properties to.
Call it first, if you implement your own algrorithm, and serialize to the returned object!
Parameters:
Name Type Description newObject
Object Object to where you'll serialize
seenObjects
Object Already seen objects
- Inherited From:
Returns:
Object to serialize to.
- Type
- Object
-
getValue()
-
Alias for
L.ALS.Widgets.Button#getButtonText
- Overrides:
Returns:
Button's text
- Type
- string
-
<protected> onChange(event)
-
Being called when user changes this widget. Override it to add your functionality like validation.
Default implementation just returns true.
Parameters:
Name Type Description event
Event Event fired by input
- Inherited From:
Returns:
If true, the attached callback will be called.
- Type
- boolean
-
serialize(seenObjects)
-
Serializes this object to JSON. If overridden, you MUST perform following operations before returning JSON:
let json = {} // Your JSON ... // Perform serialization json.constructorArguments = this.serializeConstrutorArguments(); // Serialize constructor arguments json.serializableClassName = this.serializableClassName; // Add class name to JSON return json; // Finally return JSON
Parameters:
Name Type Description seenObjects
Object Already seen objects
- Inherited From:
Returns:
This serialized object
- Type
- Object
-
serializeConstructorArguments()
-
Serializes constructor arguments. If your constructor is not empty, result of this method MUST be added to json at
L.ALS.Serializable#serialize
as "_construtorArgs" property.Deprecated in favor of
L.ALS.Serializable#getObjectFromSerialized
which uses this function under-the-hood.- Inherited From:
- Deprecated:
-
- Yes
Returns:
Serialized constructor arguments
- Type
- Array
-
setButtonText(text)
-
Sets button text
Parameters:
Name Type Description text
string text to set. Pass locale property to localize it.
Returns:
This
- Type
- L.ALS.Widgets.Button
-
setConstructorArguments(args)
-
Sets constructor arguments for serialization
Parameters:
Name Type Description args
Arguments to set
- Inherited From:
-
setEnabled(isEnabled)
-
Sets whether this widget should be enabled or not
Parameters:
Name Type Description isEnabled
boolean - Inherited From:
Returns:
This
-
setLabelText(text)
-
Sets label text
Parameters:
Name Type Description text
string Text to set. Pass locale property to localize the label.
- Inherited From:
Returns:
This
-
setMobileIcon(mobileIcon)
-
Sets mobile icon - a class appended to this button if user's device is a phone.
Can be used for setting an icon instead of text to save up space and avoid word wrapping.
You can use Remix Icon classes to do so. Or you can install your own icon pack (not recommended due to inconsistency) and use it this way.
To remove a mobile icon, pass an empty string.
Parameters:
Name Type Description mobileIcon
string Icon to set
Returns:
This
- Type
- L.ALS.Widgets.Button
-
setValue(value)
-
Alias for
L.ALS.Widgets.Button#setButtonText
Parameters:
Name Type Description value
string Text to set
- Overrides:
Returns:
This
- Type
- L.ALS.Widgets.Button
-
shouldIgnoreEvent(event)
-
Whether ALS should ignore given event. If returns true, both
L.ALS.Widgets.BaseWidget#onChange
and (L.ALS.Widgets.BaseWidget#callCallback
) won't be called, and none of the input's attributes will change.event.preventDefault()
won't be called though.Useful for precise control over your widget's behavior. For example, if your widget doesn't behave correctly when working with keyboard, here you can detect which actions shouldn't affect your widget.
You can also use
event.preventDefault()
here.Parameters:
Name Type Description event
Event Event that should be passed or ignored.
- Inherited From:
Returns:
True, if event should be skipped.
- Type
- boolean
-
<protected> toHtmlElement()
-
Builds this widget, i.e. creates container and puts label and input here.
Default implementation is:
let container = this.createContainer(); container.appendChild(this.createLabel()); container.appendChild(this.createInput()); return container;
- Inherited From:
- Overrides:
Returns:
HTML representation of this widget
- Type
- HTMLDivElement