Button
Extends | ButtonBase |
---|---|
Namespace | Limbo.Forms.Models.Fields |
Type | button |
The Button
class represents a normal HTML button similar to writing <button type="button"></button>
.
Properties
The class has the following properties:
C# Name | C# Type | JSON Name | Description |
---|---|---|---|
Type |
string |
type |
Inherited from the FieldBase class.The type of the field - generally matching the HTML |
Name |
string |
name |
Inherited from the FieldBase class.The name of the field - matching the value for the HTML `name` attribute. |
Label |
string |
label |
Inherited from the FieldBase class.A friendly name that should accompany the field. |
Description |
string |
description |
Inherited from the FieldBase class.A description that should accompany the field. |
IsRequired |
bool |
required |
Inherited from the FieldBase class.Whether the field is required/mandatory. |
Value |
object |
value |
Inherited from the FieldBase class.An optional value of the field. |
Usage
The package supports a few different ways to add a button - eg. via an extension method directly on the form:
form.AddButton("myButton", "My button");
The extension method doesn't support all properties available for a button, but adds a shortcut for easier adding simple buttons.
For a bit more control, you can initialize a new Button
class and add it the the form's Fields
property:
form.Fields.Add(new Button {
Name = "myButton",
Label = "My button",
IsRequired = true,
Description = "This button is required, although this is a little weird for a button.",
Value = "I can has value?"
});
JSON Output
In it's simplest form, a button field will be serialized to JSON as:
{
"type": "button",
"name": "myButton",
"label": "My button"
}
but with more properties specified, it may look like this:
{
"type": "button",
"name": "myButton",
"label": "My button",
"description": "This button is required, although this is a little weird for a button.",
"required": true,
"value": "I can has value?"
}