Detect Abbreviations in Form Entries
Abbreviation detection recognizes shortened forms, acronyms, and shorthand in entered text, then expands them, suggests a full term, or flags ambiguous usage. Examples include BP → Blood Pressure, NYC → New York City, and MS, which can have multiple meanings in clinical settings.
To detect abbreviations in SurveyJS, register a custom asynchronous function and add async expression validators to a question's validators array. You can also expand recognized abbreviations in the onValueChanged event handler.
How This Demo Works
- An in-demo terminology dictionary simulates a reference data source.
- Common department abbreviations expand automatically (for example,
HRbecomesHuman Resources). - Other fields use async expression validators that call the
isAbbreviationAcceptablefunction. - If an abbreviation issue is detected, the function returns
false, and the field displays the validatortext.
In this demo, validators use "notificationType": "warning", so validation messages do not block form submission. To prevent the form from being submitted until the issue is resolved, use the default "error" notification type.
Connect to an API Endpoint
To validate against a terminology service, dictionary, or natural language processing (NLP) endpoint, replace the demo helper with a fetch call (or an equivalent call using your SDK). Keep the same registerFunction and expression validator:
function isAbbreviationAcceptable([fieldName, value]) {
if (!value) {
this.returnResult(true);
return;
}
fetch("/api/validation/abbreviations", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ fieldName, value })
})
.then((response) => response.json())
.then((data) => {
// data.ok === true means the value is acceptable
this.returnResult(!!data.ok);
})
.catch(() => {
this.returnResult(false);
});
}
registerFunction({
name: "isAbbreviationAcceptable",
func: isAbbreviationAcceptable,
isAsync: true
});
Add expression validators to your survey JSON, for example: "expression": "isAbbreviationAcceptable('location', {location})". Refer to the JSON schema in the Code tab for more examples.