How to read new line in a textarea form using bootstrap? - string

I´m making a form using twitter-bootstrap
One of them is a form control which supports multiple lines of text
<textarea class="form-control" id="resumen" rows="1"></textarea>
then I read the contents
texto = $('#resumen').val()+'\r\n'
for example if user enters into id resumen form:
hello world
hello world again
texto = hello world hello world again
How can I read new lines in the form ?
The full string is a line and do not read the 'new lines' added (using enter) by the user.
I would like to read the full string with diferent lines, as the user enter it
How can I do that?

New lines are there, if you read and print that input string in console you will see new lines are coming.
If you want to print that input string in html then replace those new lines by <br>,
If you want to play with each line break them into array
<textarea id="textarea"></textarea>
read
<script type="text/javascript">
function readTextArea () {
var data = $("#textarea").val();
var dataNlToBr = data.replace(/\r?\n/g, '<br>');
var dataArray = dataNlToBr .split('<br>');
console.log(data);
console.log(dataNlToBr);
console.log(dataArray);
}
</script>

Related

Save xlsl file with Hebrew as txt to load into Photoshop data sets

I have an Excel (xlsx) file that has 3 columns of data that is set to replace said data in a Photoshop file (PSD), to do so I need to load it into Photoshop in a txt format, encoded to ANSI, so that Photoshop can read that file, and export it a bunch of times each time with the next row's properties.
However my Excel file has some Hebrew text, that is lost when encoding to ANSI, I tried other encodings but Photoshop doesn't accept them, how can I still feed Photoshop with the Hebrew data? (It's a lot of photos so I can't do it manually one by one)
This works for me: I've got a simple text file, with some Hebrew text on it.
And from Photoshop:
var myfile = "D:\\temp\\hebrew.txt"; // change this
var text = read_it(myfile);
alert(text);
// השועל החום המהיר קופץ מעל הכלב העצלן.
// function READ IT (filename with path) :returns string
// ----------------------------------------------------------------
function read_it(afilepath)
{
var theFile = new File(afilepath);
//read in file
var words = ""; // text collection string
var theTextFile = new File(theFile);
theTextFile.open('r');
while(!theTextFile.eof)
{
var line = theTextFile.readln();
if (line != null && line.length >0)
{
words += line + "\n";
}
}
theTextFile.close();
// return string
return words;
}

How can i show a pie chart using portlet script type(SuiteScript 2.0) in netsuite?and also How to include a HTML file in our portlet script.?

function() {
function render(params)
{
params.portlet.title = 'My Portlet';
var content = '<body>'+
'<form>' +
' <fieldset>'+
' <legend>Selecting elements </legend> ' +
'<p> <label>Select Range</label> <select id = "myList"><option value = "1">Daily</option> <option value = "2">Weekly</option>'+
' <option value = "3">Monthly</option> <option value = "4">Yearly</option>' +
' </select>' +
' </p>' +
' </fieldset>' +
'</form>' +
' </body>';
params.portlet.html = content;
}
Can you guys help me in writing code for pie chart . and provide me some syntax for calling other scripts from portlet.
I've tried adding a select field( Drop down) using html in netsuite and it is working fine. But i want pie chart in my UI.
NetSuite runs JavaScript/HTML/CSS like everything else. I would make an HTML file holding everything you need (JavaScript, CSS, and any plotting libraries), and open it with localhost to check things out. When you have that the way you like it, pick the option that works for you to port that into NetSuite:
Copy the text to var content = "your_html_here" (will likely be a pain to maintain but will work fine).
Load the HTML file into your file cabinet, and load it into your portlet script to do text replacing to insert any data you need (one extra step, but much easier to maintain and you can pull down the HTML file to do any local testing you need):
var content = file.load({id: /Suitescripts/path_to_your_html_file.html"}).getContents()
content = content.replace("Placeholder_Text", "With This")
Since you're asking how to build a pie chart, I would recommend using something like d3js where you might be able to build off this example of a pie chart.
If you get stuck, or need some help, comment back down below. There's no such thing as a stupid question, promise!
EDIT
You asked about adding search results to your HTML file. Although it sounds like you've answered your question, I will document the process here just in case, never know whose coming here from Google!
var mySearch = search.load({id: "my_search_id", ...})
mySearch.run.each(function(result) {
searchHTML += "<tr>"
searchHTML += `<td>${result.getText({name: "fieldname", ... })}</td>`
searchHTML += `<td>${result.getValue({name: "fieldname", ... })}</td>`
searchHTML += "</tr>"
// To move onto the next result
return true;
})
Hope that helps!

How to put text in between a paragraph <p></p> tag on python/selenium?

I'm testing some automation on a website and I encountered a <p> tag inside an iframe. I need to populate some text specifically between the <p></p> tags.
I've already tried using .text() = 'some text' but it does not work
I've also tried doing .text('some text') with no success
I was just recently initiated into python and selenium so this is really hard to figure out for some reason
Python Code
from selenium import webdriver
browser.get('www.somewebsite.com')
iframe = browser.find_element_by_id('IFR1')
browser.switch_to.frame(iframe)
browser.find_element_by_tag_name("p").text() = 'this is a txt test'
print('success')
I expect the <p> tag to have 'this is a txt text' but nothing happens
browser.find_element_by_tag_name("p").innerHTML = 'this is a txt test'
OR
browser.find_element_by_tag_name("p").innerText = 'this is a txt test'
OR
aEle = browser.find_element_by_tag_name("p")
aEle.setAttribute("innerHTML","this is a txt test")
After a lot of trial and error I was able to use ActionChains(browser).send_keys('this is a test').perform() in order to achieve writing some text inside the tags
Maybe you can try this:
browser.find_element_by_tag_name("p").send_keys('this is a txt test')
print('success')

Bind breakline symbol to Label.Text

When binding a Label.Text
have tried many ways:
\n \r
but none of them are being displayed as breakline
I refuse to believe I will need to dynamically create a Custom control to generate spans on numbers of breakline symbol...
is there any easier/simpler approach ?
What I've tried:
string BreaklineText = "Text first line\nText second line"
string BreaklineText = "Text first line\rText second line"
string BreaklineText = #"Text first line
Text second line"
string BreaklineText = #"Text first line
Text second line"
The xaml:
<Label Text="{Binding BreaklineText}"/>
It should be displayed on my view as
Text first line
Text second line
It's not the optimal solution since I wanted to find a symbol that could be interpreted as BreakLine on XAML, but it will do the job.
string BreaklineText = "Text first line\nText second line".Replace("\n", System.Environment.NewLine);
using Ascii equivalent
in XAML should work, you have missed ;
<Label Text="Text first line
Text second line"/>
I built on #Motumbo and set System.Environment.NewLine to a variable like
var nl = System.Environment.NewLine;
then I could write variations on:
string text = "some text" + nl + "text on newline";
Also found that "\r\n" works on Droid and UWP. Did not have iOS to test. So:
string text = "some text\r\ntext on newline";
worked for me.

Insert image into a specified location

I have a Google Apps script which replaces placeholders in a copy of a template document with some text by calling body.replaceText('TextA', 'TextB');.
Now I want to extend it to contain images. Does anybody have idea how to do this?
Thank you,
Andrey
EDIT: Just to make it clear what my script does. I have a Google form created in a spreadsheet. I've created a script which runs upon form submission, traverses a sheet corresponding to the form, find unprocessed rows, takes values from corresponding cells and put them into a copy of a Google document.
Some fields in the Google form are multi-line text fields, that's where '\r\r' comes from.
Here's a workaround I've come up with by now, not elegant, but it works so far:
// replace <IMG src="URL"> with the image fetched from URL
function processIMG_(Doc) {
var totalElements = Doc.getNumChildren();
for( var j = 0; j < totalElements; ++j ) {
var element = Doc.getChild(j);
var type = element.getType();
if (type =='PARAGRAPH'){
var par_text = element.getText();
var start = par_text.search(new RegExp('<IMG'));
var end = par_text.search(new RegExp('>'));
if (start==-1)
continue;
// Retrieve an image from the web.
var url = getURL_(par_text.substring(start,end));
if(url==null)
continue;
// Before image
var substr = par_text.substring(0,start);
var new_par = Doc.insertParagraph(++j, substr);
// Insert image
var resp = UrlFetchApp.fetch(url);
new_par.appendInlineImage(resp.getBlob());
// After image
var substr = par_text.substring(end+1);
Doc.insertParagraph(++j, substr);
element.removeFromParent();
j -= 2; // one - for latter increment; another one - for increment in for-loop
totalElements = Doc.getNumChildren();
}
}
}
Here is a piece of code that does (roughly) what you want.
(there are probably other ways to do that and it surely needs some enhancements but the general idea is there)
I have chosen to use '###" in the doc to mark the place where the image will be inserted, the image must be in your google drive (or more accurately in 'some' google drive ).
The code below uses a document I shared and an image I shared too so you can try it.
here is the link to the doc, don't forget to remove the image and to put a ### somewhere before testing (if ever someone has run the code before you ;-)
function analyze() { // just a name, I used it to analyse docs
var Doc = DocumentApp.openById('1INkRIviwdjMC-PVT9io5LpiiLW8VwwIfgbq2E4xvKEo');
var image = DocsList.getFileById('0B3qSFd3iikE3cF8tSTI4bWxFMGM')
var totalElements = Doc.getNumChildren();
var el=[]
for( var j = 0; j < totalElements; ++j ) {
var element = Doc.getChild(j);
var type = element.getType();
Logger.log(j+" : "+type);// to see doc's content
if (type =='PARAGRAPH'){
el[j]=element.getText()
if(el[j]=='###'){element.removeFromParent();// remove the ###
Doc.insertImage(j, image);// 'image' is the image file as blob
}
}
}
}
EDIT : for this script to work the ### string MUST be alone in its paragraph, no other character before nor after... remember that each time one forces a new line with ENTER the Document creates a new paragraph.

Resources