Accepting data in form of column, converting to string
Jul 19, 2023 07:24 PM(2448 views)
I'm trying to do the following:
Accept this input from user:
A1234965 A1233339 A1234736 A123494Z A1233114
Convert it to the string: "A1234965,A1233339,A1234736,A123494Z,A1233114"
With no limit on how long the inputted "column" is. I want the user to paste the "column" into a popup window that asks for it, then store that data as the string above. My real problem is finding a way to accept that input from the user ("text edit box" won't let a column-format be pasted). Then, of course, I don't know how to convert that input into the string format I need. Any help would be appreciated. Thanks!
You will have to split the data first using Words() before using Concat Items(). Depending where the data is being pasted from, sometimes you might have to perform some substitutions before using Words(). These can be done with Regex() using GLOBALREPLACE or Substitute()/Substitute Into().
It also might be good idea to remove duplicates (Associative Arrays can be used for this, if it doesn't matter that they will be ordered alphabetically).
It sounds like you're set on how to parse the entry, but that the display of the entry is giving you issues. It may seem like the text edit box is only taking in one line when in fact all the lines are pasting just fine, but the height of the box isn't allowing you to see them (if you arrow up and down in the edit box you'll see the other lines).
What I would do is pre-size the edit box when making the dialog to roughly the expected size of the paste. You can do that by adding something like:
Lots = "abc";
w = New Window("Lot(s) of Interest",
Border Box(top(50), bottom(50), Left(50), Right(50),
V List Box(
H Center Box(Text Box("Lot(s) of Interest Input")),
Spacer Box(size(1, 30)),
H List Box(Text Box("Lots: "), b1 = Text Edit Box(Lots)),
Spacer Box(size(1, 10)),
H Center Box(
Button Box("Save",
Lots = b1 << get text;
w << closeWindow;
)
)
)
)
);
b1<<SetNLines(10)<<set width(150);
Re: Accepting data in form of column, converting to string
Created:
Jul 19, 2023 11:12 PM
| Last Modified: Jul 19, 2023 9:58 PM(2436 views)
| Posted in reply to message from txnelson 07-19-2023
Thank you, I'll definitely be using the concat function. My big problem is taking in the user input. They'd be copying a column from a datatable and pasting it into an edit box. In my current code (seen below), it'll only take the first cell of the copied column... I'm assuming this is because I'm using a "Text Edit Box" and the Text data type - is there an edit box and data type that could take data formatted like this?:
A1234965 A1233339 A1234736 A123494Z A1233114
Here's my current code:
Lots = "abc";
w = New Window("Lot(s) of Interest",
Border Box(top(50), bottom(50), Left(50), Right(50),
V List Box(
H Center Box(Text Box("Lot(s) of Interest Input")),
Spacer Box(size(1, 30)),
H List Box(Text Box("Lots: "), b1 = Text Edit Box(Lots)),
Spacer Box(size(1, 10)),
H Center Box(
Button Box("Save",
Lots = b1 << get text;
w << closeWindow;
)
)
)
)
);
You will have to split the data first using Words() before using Concat Items(). Depending where the data is being pasted from, sometimes you might have to perform some substitutions before using Words(). These can be done with Regex() using GLOBALREPLACE or Substitute()/Substitute Into().
It also might be good idea to remove duplicates (Associative Arrays can be used for this, if it doesn't matter that they will be ordered alphabetically).
Thank you, this helps tons. I'm still having an issue converting the input into a list, formatted like so: {"aa", "bb", "cc"}. I would've thought the words function would work right away, as the input is just a long string.... but I'm probably doing something wrong. I attached a screenshot of my log.
You missed including the appropriate delimiter in the Words() function. In your case you want an end of line character (or characters) as the delimiter. See the table of Escape Sequences for Quoted Strings in the JSL syntax rules.
Try this:
Names Default To Here( 1 );
Lots = "abc";
w = New Window( "Lot (s) of Interest",
Border Box( top( 50 ), bottom( 50 ), Left( 50 ), Right( 50 ),
V List Box(
H Center Box( Text Box( "Lot (s) of Interest Input" ) ),
Spacer Box( size( 1, 30 ) ),
H List Box( Text Box( ("Lots: ") ), b1 = Text Edit Box( Lots, <<SetNLines( 10 ), <<set width( 150 ) ) ),
Spacer Box( size( 1, 10 ) ),
H Center Box(
Button Box( "Save",
Lots = b1 << get text;
W << close window; //include the delimiters for carriage and new line in the Words() function
newlots = Words( Lots, "\!r\!n" );
Show( Lots );
Show( newlots );
)
)
)
)
);
It sounds like you're set on how to parse the entry, but that the display of the entry is giving you issues. It may seem like the text edit box is only taking in one line when in fact all the lines are pasting just fine, but the height of the box isn't allowing you to see them (if you arrow up and down in the edit box you'll see the other lines).
What I would do is pre-size the edit box when making the dialog to roughly the expected size of the paste. You can do that by adding something like:
Lots = "abc";
w = New Window("Lot(s) of Interest",
Border Box(top(50), bottom(50), Left(50), Right(50),
V List Box(
H Center Box(Text Box("Lot(s) of Interest Input")),
Spacer Box(size(1, 30)),
H List Box(Text Box("Lots: "), b1 = Text Edit Box(Lots)),
Spacer Box(size(1, 10)),
H Center Box(
Button Box("Save",
Lots = b1 << get text;
w << closeWindow;
)
)
)
)
);
b1<<SetNLines(10)<<set width(150);
Re: Accepting data in form of column, converting to string
Created:
Jul 20, 2023 10:47 AM
| Last Modified: Jul 20, 2023 8:16 AM(2369 views)
| Posted in reply to message from aidanweb 07-20-2023
Like I said earlier, use Words() to split it into a list. Then use Concat Items() to combine that list back to a string. It might be enough to use \!N as separator with Words() but sometimes it might not work correctly
As this can be fairly common task to do with JSL below is complete example. This example does contain some a bit more advanced techniques which can be used when building user-interfaces with JSL, so it is a good idea to start with the example @julian provided first.
Names Default To Here(1);
lotquery = ""; // initialize as empty
initial_input = "A1234965
A1233339
A1234736
A123494Z
A1233114
A1233114";
nw = New Window("Lot(s) of Interest", Show Toolbars(0), Show Menu(0),// << modal,
Border Box(top(10), bottom(5), Left(20), Right(20),
V List Box(align("center"),
Text Box("Input lots of interest:"),
Text Edit Box(initial_input, << Set NLines(10), << set width(250)), // << Set Text Changed or << Set Function can be used for cleanup during input
Spacer Box(size(300, 10)), // Use wide spacer box to easily force window width
Panel Box("Actions",
Lineup Box(N Col(2),
Button Box("OK",
<< Set Function(function({this},
Local({input_values, input_list},
input_values = (this << top parent)[Text Edit Box(1)] << get text;
If(IsMissing(input_values), // very lazy check
Throw("No lots provided!");
);
input_list = Associative Array(Words(input_values, "\!N")) << get keys; // aa to remove duplicates
lotquery = "'" || Concat Items(input_list, "', '") || "'";
);
write("Input lots: " || lotquery);
(this << top parent) << Close Window;
));
),
Button Box("Close",
<< Set Function(function({this},
(this << top parent) << Close Window;
))
)
)
)
)
),
<< Set Window Icon("WebBrowserImportAsData")
);
/* // if modal is used
If(nw["Button"] != 1,
Throw("Cancel pressed");
);
If(IsMissing(lotquery),
Throw("No lots provided!");
);
*/
Write();
-Jarmo
'
var data = div.getElementsByClassName("video-js");
var script = document.createElement('script');
script.src = "https://players.brightcove.net/" + data_account + "/" + data_palyer + "_default/index.min.js";
for(var i=0;i< data.length;i++){
videodata.push(data[i]);
}
}
}
for(var i=0;i< videodata.length;i++){
document.getElementsByClassName('lia-vid-container')[i].innerHTML = videodata[i].outerHTML;
document.body.appendChild(script);
}
}
catch(e){
}
/* Re compile html */
$compile(rootElement.querySelectorAll('div.lia-message-body-content')[0])($scope);
}
if (code_l.toLowerCase() != newBody.getAttribute("slang").toLowerCase()) {
/* Adding Translation flag */
var tr_obj = $filter('filter')($scope.sourceLangList, function (obj_l) {
return obj_l.code.toLowerCase() === newBody.getAttribute("slang").toLowerCase()
});
if (tr_obj.length > 0) {
tr_text = "This post originally written in lilicon-trans-text has been computer translated for you. When you reply, it will also be translated back to lilicon-trans-text.".replace(/lilicon-trans-text/g, tr_obj[0].title);
try {
if ($scope.wootMessages[$rootScope.profLang] != undefined) {
tr_text = $scope.wootMessages[$rootScope.profLang].replace(/lilicon-trans-text/g, tr_obj[0].title);
}
} catch (e) {
}
} else {
//tr_text = "This message was translated for your convenience!";
tr_text = "This message was translated for your convenience!";
}
try {
if (!document.getElementById("tr-msz-" + value)) {
var tr_para = document.createElement("P");
tr_para.setAttribute("id", "tr-msz-" + value);
tr_para.setAttribute("class", "tr-msz");
tr_para.style.textAlign = 'justify';
var tr_fTag = document.createElement("IMG");
tr_fTag.setAttribute("class", "tFlag");
tr_fTag.setAttribute("src", "/html/assets/lingoTrFlag.PNG");
tr_fTag.style.marginRight = "5px";
tr_fTag.style.height = "14px";
tr_para.appendChild(tr_fTag);
var tr_textNode = document.createTextNode(tr_text);
tr_para.appendChild(tr_textNode);
/* Woot message only for multi source */
if(rootElement.querySelector(".lia-quilt-forum-message")){
rootElement.querySelector(".lia-quilt-forum-message").appendChild(tr_para);
} else if(rootElement.querySelector(".lia-message-view-blog-topic-message")) {
rootElement.querySelector(".lia-message-view-blog-topic-message").appendChild(tr_para);
} else if(rootElement.querySelector(".lia-quilt-blog-reply-message")){
rootElement.querySelector(".lia-quilt-blog-reply-message").appendChild(tr_para);
} else if(rootElement.querySelector(".lia-quilt-tkb-message")){
rootElement.querySelector(".lia-quilt-tkb-message").appendChild(tr_para);
} else if(rootElement.querySelector(".lia-quilt-tkb-reply-message")){
rootElement.querySelector(".lia-quilt-tkb-reply-message").insertBefore(tr_para,rootElement.querySelector(".lia-quilt-row.lia-quilt-row-footer"));
} else if(rootElement.querySelector(".lia-quilt-idea-message")){
rootElement.querySelector(".lia-quilt-idea-message").appendChild(tr_para);
}else if(rootElement.querySelector(".lia-quilt-column-alley-left")){
rootElement.querySelector(".lia-quilt-column-alley-left").appendChild(tr_para);
}
else {
if (rootElement.querySelectorAll('div.lia-quilt-row-footer').length > 0) {
rootElement.querySelectorAll('div.lia-quilt-row-footer')[0].appendChild(tr_para);
} else {
rootElement.querySelectorAll('div.lia-quilt-column-message-footer')[0].appendChild(tr_para);
}
}
}
} catch (e) {
}
}
} else {
/* Do not display button for same language */
// syncList.remove(value);
var index = $scope.syncList.indexOf(value);
if (index > -1) {
$scope.syncList.splice(index, 1);
}
}
}
}
}
}
angular.forEach(mszList_l, function (value) {
if (document.querySelectorAll('div.lia-js-data-messageUid-' + value).length > 0) {
var rootElements = document.querySelectorAll('div.lia-js-data-messageUid-' + value);
}else if(document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view').length >0){
var rootElements = document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view')[0].querySelectorAll('.lia-occasion-description')[0];
}else {
var rootElements = document.querySelectorAll('div.message-uid-' + value);
}
angular.forEach(rootElements, function (rootElement) {
if (value == '660390' && "ForumTopicPage" == "TkbArticlePage") {
rootElement = document.querySelector('.lia-thread-topic');
}
/* V1.1 Remove from UI */
if (document.getElementById("tr-msz-" + value)) {
document.getElementById("tr-msz-" + value).remove();
}
if (document.getElementById("tr-sync-" + value)) {
document.getElementById("tr-sync-" + value).remove();
}
/* XPath expression for subject and Body */
var lingoRBExp = "//lingo-body[@id = " + "'lingo-body-" + value + "'" + "]";
lingoRSExp = "//lingo-sub[@id = " + "'lingo-sub-" + value + "'" + "]";
/* Get translated subject of the message */
lingoRSXML = doc.evaluate(lingoRSExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < lingoRSXML.snapshotLength; i++) {
/* Replace Reply/Comment subject with transalted subject */
var newSub = lingoRSXML.snapshotItem(i);
/*** START : extracting subject from source if selected language and source language is same **/
var sub_L = "";
if (newSub.getAttribute("slang").toLowerCase() == code_l.toLowerCase()) {
if (value == '660390') {
sub_L = decodeURIComponent($scope.sourceContent[value].subject);
}
else{
sub_L = decodeURIComponent($scope.sourceContent[value].subject);
}
} else {
sub_L = newSub.innerHTML;
}
/*** End : extracting subject from source if selected language and source language is same **/
/* This code is placed to remove the extra meta tag adding in the UI*/
try{
sub_L = sub_L.replace('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />','');
}
catch(e){
}
// if($scope.viewTrContentOnly || (newSub.getAttribute("slang").toLowerCase() != code_l.toLowerCase())) {
if ($scope.viewTrContentOnly) {
if ("ForumTopicPage" == "IdeaPage") {
if (value == '660390') {
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
document.querySelector('.MessageSubject .lia-message-subject').innerHTML = sub_L;
}
}
}
if ("ForumTopicPage" == "TkbArticlePage") {
if (value == '660390') {
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
var subTkbElement = document.querySelector('.lia-thread-subject');
if(subTkbElement){
document.querySelector('.lia-thread-subject').innerHTML = sub_L;
}
}
}
}
else if ("ForumTopicPage" == "BlogArticlePage") {
if (value == '660390') {
try {
if((sub_L != "") && (sub_L!= undefined) && (sub_L != "undefined")){
var subElement = rootElement.querySelector('.lia-blog-article-page-article-subject');
if(subElement) {
subElement.innerText = sub_L;
}
}
} catch (e) {
}
/* var subElement = rootElement.querySelectorAll('.lia-blog-article-page-article-subject');
for (var subI = 0; subI < subElement.length; subI++) {
if((sub_L != "") && (sub_L!= undefined) && (sub_L != "undefined")){
subElement[subI].innerHTML = sub_L;
}
} */
}
else {
try {
// rootElement.querySelectorAll('.lia-blog-article-page-article-subject').innerHTML= sub_L;
/** var subElement = rootElement.querySelectorAll('.lia-blog-article-page-article-subject');
for (var j = 0; j < subElement.length; j++) {
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
subElement[j].innerHTML = sub_L;
}
} **/
} catch (e) {
}
}
}
else {
if (value == '660390') {
try{
/* Start: This code is written by iTalent as part of iTrack LILICON - 98 */
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
if(document.querySelectorAll('.lia-quilt-forum-topic-page').length > 0){
if(rootElement.querySelector('div.lia-message-subject').querySelector('h5')){
rootElement.querySelector('div.lia-message-subject').querySelector('h5').innerText = decodeURIComponent(sub_L);
} else {
rootElement.querySelector('.MessageSubject .lia-message-subject').innerText = sub_L;
}
} else {
rootElement.querySelector('.MessageSubject .lia-message-subject').innerText = sub_L;
}
}
/* End: This code is written by iTalent as part of iTrack LILICON - 98 */
}
catch(e){
console.log("subject not available for second time. error details: " + e);
}
} else {
try {
/* Start: This code is written by iTalent as part of LILICON - 98 reported by Ian */
if ("ForumTopicPage" == "IdeaPage") {
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
document.querySelector('.lia-js-data-messageUid-'+ value).querySelector('.MessageSubject .lia-message-subject').innerText = sub_L;
}
}
else{
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
rootElement.querySelector('.MessageSubject .lia-message-subject').innerText = sub_L;
/* End: This code is written as part of LILICON - 98 reported by Ian */
}
}
} catch (e) {
console.log("Reply subject not available. error details: " + e);
}
}
}
// Label translation
var labelEle = document.querySelector("#labelsForMessage");
if (!labelEle) {
labelEle = document.querySelector(".LabelsList");
}
if (labelEle) {
var listContains = labelEle.querySelector('.label');
if (listContains) {
/* Commenting this code as bussiness want to point search with source language label */
// var tagHLink = labelEle.querySelectorAll(".label")[0].querySelector(".label-link").href.split("label-name")[0];
var lingoLabelExp = "//lingo-label/text()";
trLabels = [];
trLabelsHtml = "";
/* Get translated labels of the message */
lingoLXML = doc.evaluate(lingoLabelExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
/* try{
for(var j=0;j,';
}
trLabelsHtml = trLabelsHtml+'