I am saving the below div tag into SQL DB:
String StrDiv = "<div STYLE=" + "''"+"font-family: " + lblPreviewPane.Font.Name + "; font-size: " + lblPreviewPane.Font.Size + "; color: " + ColorPicker1.Color + ""+"''" + ">" + lblPreviewPane.Text + "</div>";
The below query is used to update the message:
String sqlUpdate = "update iweb_messages set message='" + StrDiv +
"'where site_id ='" + mSiteID + "' and page_id ='" + ddlSitePage.SelectedValue + "'";
I retrieve the div from DB and display it in a textbox and a label.
In the label, the div tag is displayed as: messagetoday21
But in the textbox, the div tag is displayed as:
<div STYLE='font-family: Times New Roman; font-size: 18pt; color: #CC3399'>today21</div>
I need to display the text alone in the textbox also(same as displayed in the Label).
Kindly help me with some suggestions.
I use the below code to display the text from the DB in the textbx and label:
String sqlMsg = "select message from iweb_messages where site_id='" + mSiteID + "' and page_id='" + ddlSitePage.SelectedValue + "'";
DataView dvMsg = dbLib.GetDateView(sqlMsg);
if (dvMsg.Table.Rows.Count > 0)
{
txtOutputMessage.Text = dvMsg.Table.Rows[0]["message"].ToString();
lblPreviewPane.Text = dvMsg.Table.Rows[0]["message"].ToString();
}
I assume your "textbox" is a textarea? If so, the behavior you're seeing is expected, because you're generating HTML that looks like this:
<textarea><div STYLE='font-family.....></div></textarea>
The content of a TEXTAREA is displayed without HTML rendering. Whereas the label (assuming it's a span or another div) will render the HTML.
So, as a quick fix, you need to save lblPreviewPane.Text to your database in addition to the full <div>; then display the value of lblPreviewPane.Text in your text box instead of the <div>.
But I would also question the wisdom of storing the full <div> in the database. If the font attributes need to be determined ahead of time, then I think you would be better off storing those attribute values in the table, then building the formatted <div> when it is being displayed.
Related
May I know how to put the elements I get from HtmlWidget(allwordlist![0].ivakavakayagataki.toString()), HtmlWidget(allwordlist![0].ivakavakayagataki.toString()), in a paragraph?
I am making a dictionary application and the above HTML render code works but problem is that I cannot seem to find a way to put these two in a paragraph as in side by side like a sentence.
May I get some help un knowing how to do this please.
Thanks in advance.
Ok so I made it work.
So I first made this function and not that <p> tags so the problem thats was making my HtmlWidget statement not inline and having line breaks was because of the p tag so I first took it out.
Widget mergehtml(String html1, String html2,){
html1 = html1.replaceAll("<p>", "").replaceAll("</p>", "");
html2 = html2.replaceAll("<p>", "").replaceAll("</p>", "");
String mergedHtml = "<p style='font-size:18px;'>" + html1 + " " + "[" + html2 + "], " + "</p>" ;
return HtmlWidget(mergedHtml);
}
and then I called it and put my two variables there.
mergehtml("${allwordlist![0].tina}","${allwordlist![0].itavi}",)
it then started working inline.
Thanks :)
I've created a script one or two years ago, which exports all strings for Android and iOS.
It shows a dialog with textareas for each language with the full strings file in the textarea.
It always worked fine until UiApp was removed.
So right now I've tried using HtmlService and HtmlTemplate. Both result in & being converted to &.
HtmlOutput I'm using this code:
var htmlOutput = HtmlService.createHtmlOutput().setWidth(800).setHeight(600);
htmlOutput.append('<textarea style="width: 100%; height: 100px;" id="' + id + '">' + content + '</textarea>');
This produces a textarea with for example this:
<string name="terms">Terms & Privacy</string>
For HtmlTemplate I've tried:
var templateString = '<textarea style="width: 100%; height: 100px;" id="' + ("export_" + i) + '">' + '<?!=' + texts[i] + '?>' + '</textarea>';
// Or this one without Force-printing scriptlets
// var templateString = '<textarea style="width: 100%; height: 100px;" id="' + ("export_" + i) + '">' + texts[i] + '</textarea>';
HtmlService.createTemplate(templateString).evaluate().setWidth(800).setHeight(600);
I tried to use Force-printing scriptlets which gives an even weirder output:
Terms & Privacy
It doesn't even give the <string> tags around it. When I leave the Force-printing scriptlets away it gives the same result as HtmlOutput.
Some extra info
Before I'm exporting it using these methods I'm making sure every string is being converted so it will be the correct output for Android and iOS. For example I'm using this piece of code to convert a string:
var text = o.texts[textIndex];
text = text.replace(/&/g, "&");
'<string name="' + identifier + '">' + text + '</string>' + "\n";
This is of course not all, but just to give an idea how the script works.
Solution
You can utilize the appendUntrusted() method to return HTML without being parsed. Everything you append to output via this method will not be treated as markup (think of it as setting textContent property).
Sample
var htmlOutput = HtmlService.createHtmlOutput().setWidth(800).setHeight(600);
htmlOutput.append('<textarea style="width: 100%; height: 100px;" id="' + id + '">');
htmlOutput.appendUntrusted(content);
htmlOutput.append('</textarea>');
Output
And this is a sample output (I used '& & and two' as content)
Useful links
appendUntrusted() method reference;
You can try replacing & with literal &:
text = text.replace(/&/g, "&");
<textarea><string>Terms &Privacy</string></textarea>
<textarea></textarea>
<script>
document.querySelectorAll('textarea')[1].innerText = "Terms & Conditions"
</script>
This is a weird question about possibly embedding a string in an aurelia html file within the attribute tag but I would like to keep my tab and line formatting.
So, in my TS file I have the following:
this.queryDateStart += "type=EntityOne&dateQueryString=";
this.queryDateStart += "" +
"eOr( " +
"eAnd( " +
"eAnd( facetName:isExcluded AND facetValue:No );" +
"dAnd( facetName:deadlineDate AND "+ dateRangePredicate + ");" +
"); " +
"dOr( " +
"(facetName:excludedUntilDate AND "+ dateRangePredicate + ")" +
");" +
");"
And instead of having the following:
<section as-element="ab-deadlines" data-query="${queryDateStart}"></section>
I would like to actually pass the literal string from above.
But with the line spaces.
Would that break anything?
So for example ( going to try this today) - in my html file I would put:
<section as-element="ab-deadlines"
data-query="
eOr(
eAnd(
eAnd( facetName:isExcluded AND facetValue:No );
dAnd( facetName:deadlineDate AND ${dateRangePredicate} );
);
dOr(
(facetName:excludedUntilDate AND + ${dateRangePredicate} )
);
);"></section>
About breaking: it shouldn't break anything. In the end, it's just normal HTML attribute, and as long as the spec allows it, it works in Aurelia, as Aurelia works directly, and plainly with HTML elements.
You can see it yourself at this sandbox https://codesandbox.io/s/z20qx0q263
How can I get access and change CSS like the font color in completely dynamically generated HTML out of XML, if I cannot use an ID as I do not know in advance how many of the same HTML-tags will be generated and which of two different (red/green) colors it will need? (I am new here and very new in JS)
Data will be generated and collected on the server. I get them back and sort them in a "fieldset" and further more in a "collapsible". Data "var a, b and c" come together in one line (fieldset) and should be in a specific font color. So for "var d" there will be a "xx" or "yy" coming back from XML for this font color and be saved in "var d" and therefore the font color should be "red" or "green".
Part of my script in short:
function addPart(currentIndex,currentPart)
{
var a = $(currentPart).find("a").text();
var b = $(currentPart).find("b").text();
var c = $(currentPart).find("c").text();
var d = $(currentPart).find("d").text();
if(d === "xx") {
$("div.productColor").css({"color":"green"});
} else {
$("div.productColor").css({"color":"red"});
};
$("#shoppingTableDiv").append (
"<div data-role='collapsible'>"
+ "<h3>"
+ "<div class='productColor'>"
+ "<fieldset class='ui-grid-b'>"
+ "<div class='ui-block-a'>"
+ a
+ "</div>"
+ "<div class='ui-block-b'>"
+ b
+ "</div>"
+ "<div class='ui-block-c'>"
+ c
+ "</div>"
+ "</fieldset>"
+ "</div>"
+ "</h3>"
+ "</div>");
$('#shoppingTableDiv').collapsibleset('refresh');
}
I didn't fully understand how you want to color your results, but I think you can use your fieldset classes.
For example:
.ui-grid-b div { color: red; }
.ui-grid-c div { color: green; }
If you don't know how many fieldsets you're going to have and you can't use the fieldset classes you showed in your code example, you might find the nth-child selector useful.
Maybe something like this:
fieldset:nth-child(2n) div { color: red; }
fieldset:nth-child(2n+1) div { color: green; }
I am dynamically building html in javascript. This will then be inserted into an element. What is the correct way to set the top, left, width and height properties within the html that I am creating. My current technique works in IE, but not Chrome or Safari. This is how I'm currently doing it (controlgroup is an object containing my properties):
html += '<div id="' + controlgroup.id + '" class="controlgroup ui-widget-content"';
html += ' style="{';
html += 'top:' + controlgroup.top + '; left:' + controlgroup.left + ';';
html += 'width:' + controlgroup.width + '; height:' + controlgroup.height + ';';
html += '}">';
html += 'cg:' + controlgroup.id + ' ' + controlgroup.left + ',' + controlgroup.top;
html += '</div>';
I then do this:
$('#formcontainer').html(html);
I need the ability to specify exact coordinates, so I can't use 'predefined' css classes here. Thanks very much.
1) You'll want to make that you are using left, right, height, and width values that have px attached. So instead of setting width:50; set it to width:50px;.
2) You'll want to add position:relative; to your style.
3) The {} brackets are not needed
Working Demo: http://jsfiddle.net/Jaybles/6fbvT/2/