Option trees Dependent option trees
This example asks a user what number they would like on the sports jersey. They're always able to just type in a value. Here, we provide a sequence of dropdowns to let them select a sport, team and athlete. The jersey number is then automatically filled in.
Show source code ←// Option tree field
$("#alpaca-option-tree").alpaca({
"schema": {
"type": "number",
"title": "What number would like for your sports jersey?"
},
"options": {
"type": "optiontree",
"tree": {
"selectors": {
"sport": {
"schema": {
"type": "string"
},
"options": {
"type": "select",
"noneLabel": "Pick a Sport..."
}
},
"team": {
"schema": {
"type": "string"
},
"options": {
"type": "select",
"noneLabel": "Pick a Team..."
}
},
"player": {
"schema": {
"type": "string"
},
"options": {
"type": "select",
"noneLabel": "Pick a Player..."
}
}
},
"order": ["sport", "team", "player"],
"data": [{
"value": 23,
"attributes": {
"sport": "Basketball",
"team": "Chicago Bulls",
"player": "Michael Jordan"
}
}, {
"value": 33,
"attributes": {
"sport": "Basketball",
"team": "Chicago Bulls",
"player": "Scotty Pippen"
}
}, {
"value": 4,
"attributes": {
"sport": "Football",
"team": "Green Bay Packers",
"player": "Brett Favre"
}
}, {
"value": 19,
"attributes": {
"sport": "Baseball",
"team": "Milwaukee Brewers",
"player": "Robin Yount"
}
}, {
"value": 99,
"attributes": {
"sport": "Hockey",
"player": "Wayne Gretzky"
}
}],
"horizontal": true
},
"form": {
"buttons": {
"submit": {
"click": function() {
alert("Value is: " + this.getValue());
}
}
}
}
}
});
The following example produces the same form, but uses a connector to load the schema and options. The options JSON is loaded and merged with some inline options that provide to override a submit click handler.
Show source code ←// Using connector
$("#alpaca-option-tree-connector").alpaca({
"schemaSource": "../default/assets/demo_data/alpaca/optiontree-custom-schema.json",
"optionsSource": "../default/assets/demo_data/alpaca/optiontree-custom-options.json"
});
CKEditor field Render CKEditor editor
The ckeditor
field. The CK Editor field renders the CK editor control that allows users to visually work with HTML and save the results back into a text property. This is a full example of the CK Editor at work. The point here is to show how it looks in full. In the examples that follow, we'll trim this down. Note - CKeditor must be included in your page ahead of the control loading in order for this to work properly.
Input types Supported input types
The following example demonstrates how Alpaca library can format text inside input field. To apply lowercase
text style, set format
option to lowercase
inside schema
parameter.
// Lowercase
$("#alpaca-lowercase").alpaca({
"data": "Ice cream is wonderful.",
"schema": {
"format": "lowercase"
}
});
The following example demonstrates how Alpaca library can format text inside input field. To apply uppercase
text style, set format
option to uppercase
inside schema
parameter.
// Uppercase
$("#alpaca-uppercase").alpaca({
"data": "Ice cream is wonderful.",
"schema": {
"format": "uppercase"
}
});
The search
field implements a search box that provides a search-optimized control. It allows for the specification of search terms with an optimized user interface. It uses the HTML5 'search' input type, but not the actual search.
// Search type
$("#alpaca-search").alpaca({
"data": "Where for art thou Romeo?",
"schema": {
"type": "string"
},
"options": {
"type": "search",
"label": "Search"
}
});
The following example demonstrates integer
field with data, options and schema parameters. Minimum value is set to 18, maximum to 25. Validation is also enabled, try to change input value to see it in action.
// Integer type
$("#alpaca-integer").alpaca({
"data": 17,
"options": {
"type": "integer",
"label": "Age:",
"helper": "Guess Taylor Swift's Age"
},
"schema": {
"minimum": 18,
"maximum": 25,
"exclusiveMinimum": true,
"exclusiveMaximum": true,
"divisibleBy": 2
}
});
The following example demonstrates password
field type. Here input doesn't have any optional parameters, but a very basic setup. This input field type supports all available options and parameters.
// Password type
$("#alpaca-password").alpaca({
"data": "password",
"schema": {
"format": "password"
}
});
The following example demonstrates email
field type. Here input doesn't have any optional parameters, but a very basic setup. This input field type supports all available options and parameters. Validation enabled by default.
// Email type
$("#alpaca-email").alpaca({
"data": "support",
"schema": {
"format": "email"
}
});
The following example demonstrates ipv4
field type. Here input doesn't have any optional parameters, but a very basic setup. This input field type supports all available options and parameters. Validation enabled by default.
// IP address type
$("#alpaca-ipv4").alpaca({
"data": "100.60",
"schema": {
"format": "ip-address"
}
});
The following example demonstrates url
field type. Here input doesn't have any optional parameters, but a very basic setup. This input field type supports all available options and parameters. Validation enabled by default.
// URL type
$("#alpaca-url").alpaca({
"data": "http://www.alpacajs.org",
"options": {
"type": "url"
},
"schema": {
"format": "uri"
}
});
The following example demonstrates currency
field type. Here input doesn't have any optional parameters, but a very basic setup. The currency field uses the JQuery Price Format plugin to render format the input as it's entered.
// Currency type
$("#alpaca-currency").alpaca({
"options": {
"type": "currency"
}
});
The following example demonstrates custom personal name
field type. Every time you press space key, new word starts with capital letter. This input field type supports all available options and parameters. Validation enabled by default.
// Personal name type
$("#alpaca-name").alpaca({
"data": "Oscar Zoroaster Phadrig Isaac Norman Henkel Emmannuel Ambroise Diggs",
"options": {
"type": "personalname"
}
});
File inputs Default and optional styling
The following example demonstrates a basic single file input. This input field type supports all available options and parameters. Additionally you can specify schema format. Validation is disabled by default.
Show source code ←// Basic file input
$("#alpaca-file").alpaca({
"data": "",
"options": {
"type": "file",
"label": "Ice Cream Photo:",
"helper": "Pick your favorite ice cream picture."
},
"schema": {
"type": "string",
"format": "uri"
}
});
The following example demonstrates a basic single file input in read only
mode. This input field type supports all available options and parameters. Additionally you can specify schema format. Validation is disabled by default.
// Static mode
$("#alpaca-file-static").alpaca({
"data": "/abc.html",
"options": {
"type": "file",
"label": "Ice Cream Photo:",
"helper": "Pick your favorite ice cream picture."
},
"schema": {
"type": "string",
"format": "uri"
},
"view": "bootstrap-display"
});
The following example demonstrates a single file input styled with uniform
plugin. This is optional configuration, Alpaca doesn't support it by default and doesn't have custom field type. Also supports all available options.
// Styled file input
$("#alpaca-file-styled").alpaca({
"data": "",
"options": {
"type": "file",
"label": "Ice Cream Photo:",
"helper": "Pick your favorite ice cream picture.",
"id": "file-styled",
},
"schema": {
"type": "string",
"format": "uri"
},
"postRender": function(control) {
$("#file-styled").uniform({
fileButtonClass: 'action btn bg-blue'
});
}
});
The following example demonstrates a single file input styled with uniform
plugin in disabled
mode. This is optional configuration, Alpaca doesn't support it by default and doesn't have custom field type. Also supports all available options.
// Disabled file input
$("#alpaca-file-disabled").alpaca({
"data": "",
"options": {
"type": "file",
"label": "Ice Cream Photo:",
"helper": "Pick your favorite ice cream picture.",
"disabled": true,
"id": "file-styled-disabled"
},
"schema": {
"type": "string",
"format": "uri"
},
"postRender": function(control) {
$("#file-styled-disabled").uniform({
fileButtonClass: 'action btn bg-blue'
});
}
});
Select helpers Country and state selects
The following example demonstrates country
field with default settings. To use this kind of select helper, just set type
option to country
in your configuration.پشتیبانیs all available options.
// Country selector
$("#alpaca-country").alpaca({
"options": {
"type": "country"
}
});
The following example demonstrates state
field with default settings. To use this kind of select helper, just set type
option to state
in your configuration.پشتیبانیs all available options.
// State selector
$("#alpaca-state").alpaca({
"options": {
"type": "state"
}
});
The following example demonstrates country
field with integrated Select2 plugin. To initialize Select2 on select, you need to add init code in postRender
callback.پشتیبانیs all available options.
// Searchable country selector
$("#alpaca-country-search").alpaca({
"options": {
"type": "country",
"id": "country-search"
},
"postRender": function(control) {
$('#country-search').select2();
}
});
The following example demonstrates state
field with integrated Select2 plugin. To initialize Select2 on select, you need to add init code in postRender
callback.پشتیبانیs all available options.
// Searchable state selector
$("#alpaca-state-search").alpaca({
"options": {
"type": "country",
"id": "state-search"
},
"postRender": function(control) {
$('#state-search').select2();
}
});