Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active February 12, 2021 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/e8831521581f8e40663da81f6cc53a65 to your computer and use it in GitHub Desktop.
Save bjoerntx/e8831521581f8e40663da81f6cc53a65 to your computer and use it in GitHub Desktop.
var TXHelper = (function (tx) {
tx.textFormFields = {
convertFromSelection: function (name, id) {
// get current selection
var sel = TXTextControl.selection;
sel.getLength(function(selLength) {
if (selLength > 0) { // text is selected
sel.getText(function(selText) {
// store text
var text = selText;
sel.setText(""); // remove selected text
TXTextControl.formFields.getCanAdd(canAdd => {
if (canAdd) { // can add the field here?
// add form field
TXTextControl.formFields.addTextFormField(600, ff => {
ff.setText(text);
// set field properties
if (name) ff.setName(name);
if (id) ff.setID(id);
});
} else { // there is a field at that location
console.log("A field cannot be added at this location.");
}
});
});
}
else { // no text is selected
console.log("Nothing is selected.");
}
});
},
};
return tx;
} ( TXHelper || {} ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment