External Module Validator

An external module validator is provided by a third-party javascript resource. Confluence administrator should specify the WRM id of the resource:

images/wiki/download/attachments/44696016/Screenshot-41.png

Referenced resource should be available in the editor context, for example:

<web-resource key="blueprint-validation-resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<resource type="download" name="country.js" location="/js/modules/country.js"/>
<context>editor</context>
</web-resource>

The module shall provide two functions: focusin and focusout. The functions are invoked by the validator engine when focus is moved in and out of a table cell. User method may show a list of values or a popup (focusin) or validate the content of the cell (focusout). Below is a real code of the Country validator module:

define('com.mesilat:validator-country', ['com.mesilat/autocomplete', 'com.mesilat/autocomplete:countries'],
function(autocomplete, countries) {
 
function CountryValidator(options) {
this.id = options.code;
this.title = options.name;
 
autocomplete.ids[options.code] = {
id: options.code,
title: options.name,
getUrl: function(val) {
return val? AJS.contextPath() + '/rest/countries/1.0/find': null;
},
getParams: function(autoCompleteControl, val) {
const params = { 'max-results': 10 };
if (val) {
params.filter = Confluence.unescapeEntities(val);
}
return params;
},
update: function(autoCompleteControl, link){
countries.updateCountry(autoCompleteControl, link);
}
};
}
 
CountryValidator.prototype.focusin = function($td, empty, ed) {
if (empty) {
this.showAutocomplete(ed);
}
}
 
CountryValidator.prototype.focusout = function($td, empty, ed) {}
 
CountryValidator.prototype.showAutocomplete = function(ed) {
ed.execCommand("MesilatAutocomplete", false, { id: this.id, title: this.title }, { skip_undo: true });
}
 
return CountryValidator;
});

At runtime the validator engine will render the country picker with a flag and insert a country-and-flag macro:

images/wiki/download/attachments/44696016/Screenshot-46.png

images/wiki/download/attachments/44696016/Screenshot-47.png