Skip to content

Instantly share code, notes, and snippets.

@klinkby
Last active August 29, 2017 12:02
Show Gist options
  • Save klinkby/62b06ddd98355e8b21bd1d5eb93c9861 to your computer and use it in GitHub Desktop.
Save klinkby/62b06ddd98355e8b21bd1d5eb93c9861 to your computer and use it in GitHub Desktop.
NAV client control with a simple multiline text box
/**
* NAV client control with a simple multiline text box
* Exposes the following methods:
* GetText() : string
* SetText(string)
* GetReadOnly() : boolean
* SetReadOnly(boolean)
*
* And the following events:
* Blur
* AddInReady
*/
"use strict";
var NAV = window.Microsoft.Dynamics.NAV,
textControl = document.createElement("textarea");
function GetText() {
return textControl.value;
}
function SetText(textValue) {
textControl.value = textValue;
}
function GetReadOnly() {
return textControl.readOnly;
}
function SetReadOnly(readOnlyValue) {
textControl.readOnly = readOnlyValue;
}
// private functions
function _addEvent(element,evName,fn) {
if (element.addEventListener) {
element.addEventListener(evName,fn,false);
} else if (element.attachEvent) {
element.attachEvent('on'+evName,function(e) {
fn(e || window.event);
});
}
}
function _initializeControl(clientControlId) {
var container = document.getElementById(clientControlId);
if (!container) {
alert("Fatal: Container not found");
return;
}
textControl.style = "width: 100%; height: 100%;"
container.appendChild(textControl);
_addEvent(textControl, "blur", function () {
NAV.InvokeExtensibilityMethod("Blur", null);
});
NAV.InvokeExtensibilityMethod("AddInReady", null);
}
// Go!
_initializeControl("controlAddIn");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment