alpaca
Version:
Alpaca provides the easiest and fastest way to generate interactive forms for the web and mobile devices. It runs simply as HTML5 or more elaborately using Bootstrap, jQuery Mobile or jQuery UI. Alpaca uses Handlebars to process JSON schema and provide
117 lines (95 loc) • 2.93 kB
JavaScript
(function($) {
var Alpaca = $.alpaca;
Alpaca.Fields.URLField = Alpaca.Fields.TextField.extend(
/**
* @lends Alpaca.Fields.URLField.prototype
*/
{
/**
* @see Alpaca.Fields.TextField#getFieldType
*/
getFieldType: function() {
return "url";
},
/**
* @see Alpaca.Fields.TextField#setup
*/
setup: function()
{
// default html5 input type = "url";
this.inputType = "url";
this.base();
if (typeof(this.options.allowIntranet) === "undefined")
{
this.options.allowIntranet = false;
}
if (this.options.allowIntranet)
{
this.schema.pattern = Alpaca.regexps["intranet-url"];
}
else
{
this.schema.pattern = Alpaca.regexps.url;
}
this.schema.format = "uri";
},
/**
* @see Alpaca.Fields.TextField#handleValidate
*/
handleValidate: function() {
var baseStatus = this.base();
var valInfo = this.validation;
if (!valInfo["invalidPattern"]["status"]) {
valInfo["invalidPattern"]["message"] = this.getMessage("invalidURLFormat");
}
return baseStatus;
}
/* builder_helpers */
,
/**
* @private
* @see Alpaca.Fields.TextField#getSchemaOfOptions
*/
getSchemaOfOptions: function() {
return Alpaca.merge(this.base(), {
"properties": {
"allowIntranet": {
"title": "Allow intranet",
"description": "Allows URLs with unqualified hostnames"
}
}
});
},
/**
* @private
* @see Alpaca.Fields.TextField#getOptionsForOptions
*/
getOptionsForOptions: function() {
return Alpaca.merge(this.base(), {
"fields": {
"allowIntranet": {
"type": "checkbox"
}
}
});
},
/**
* @see Alpaca.Fields.TextField#getTitle
*/
getTitle: function() {
return "URL Field";
},
/**
* @see Alpaca.Fields.TextField#getDescription
*/
getDescription: function() {
return "Provides a text control with validation for an internet web address.";
}
/* end_builder_helpers */
});
Alpaca.registerMessages({
"invalidURLFormat": "The URL provided is not a valid web address."
});
Alpaca.registerFieldClass("url", Alpaca.Fields.URLField);
Alpaca.registerDefaultFormatFieldMapping("url", "url");
})(jQuery);