Razor Page unable to parse the < correctly - asp.net-core

Using VS2019 Version 16.6.5 Razor Page Model. Core 3.1
#{
if (Model.Mode != enAccessMode.Read)
{
<text>
$("#mTable tbody tr div").removeClass("TrError").
find("[data-title]").removeAttr("data-title");
var errs = JSAns.CollectData();
if (errs !== null) {
for (var i = 0; i < errs.length; i++) { // Razor doesn't likes the < here!!!!!
var err = errs[i];
var e = $("#mQ_" + err.ErrQID);
e.addClass("TrError");
e.attr("data-title", err.ErrMsg);
}
$("#mQ_" + errs[0].ErrQID)[0].scrollIntoView();
return;
}
</text>
}
}
The compiler doen't like the < symbol at line 9. It gives the error below during compilation. using the < doesn't help at all, since it is a javascript code, not a text string.
End of file or an unexpected character was reached before the "" tag could be parsed. Elements inside markup blocks must be complete. They must either be self-closing ("<br />") or have matching end tags ("<p>Hello</p>"). If you intended to display a "<" character, use the "<" HTML entity.

As the error shows, the razor will regard the < as the uncomplete html tag. To solve this issue, I suggest you could try below work around.
#Html.Raw("<")
Whole codes:
<text>
$("#mTable tbody tr div").removeClass("TrError").
find("[data-title]").removeAttr("data-title");
var errs = JSAns.CollectData();
if (errs !== null) {
for (var i = 0; i #Html.Raw("<") errs.length; i++) {
var err = errs[i];
var e = $("#mQ_" + err.ErrQID);
e.addClass("TrError");
e.attr("data-title", err.ErrMsg);
}
$("#mQ_" + errs[0].ErrQID)[0].scrollIntoView();
return;
}
</text>

Related

Changes reflecting in payload but is not getting applied on target widget in workdetails page in casemanager 5.2.1

In Workdetails page, under ‘Documents’ tab, when I set the alignment to ‘center’ from ‘right’ for the column value, its getting updated in payload but is not actually getting applied on target widget.
I have tried thru controller/Grid as well but its not getting set. Attached snap of same. A pointer in this regard would be of immense help.
Here is the snip:
var callbackFolderContent = function (resultset)
{
var classText = 'Abc';
var found = 0;
for (var i=0; i < resultset.length; i++)
{
var items = resultset[i].resultSet.items;
for (var j=0; j < items.length; j++)
{
var pos = id.indexOf(classText);
if(pos !== -1)
{
var PC= items[j].resultSet.structure.cells[0][3];
if(PC.styles=="text-align:right;")
{
PC.styles="text-align:center;";
var NEWpc=PC.styles; //Its reflecting in payload.
alert("Changed aligning to: "+NEWpc);
}
found ++;
} //end f if loop
} //end of inner for loop
} //end of for loop
if (found < 1)
{
payload.stateCode = 4;
payload.hideMessage=true;
abort({silent:true});
}
else
{
complete();
}
}; //end of callback function

realm react-native: how to query correctly an array of strings

can someone show me how to query an array of strings with realm in react-native?
assume i have an array like the following:
const preferences = ["automatic","suv","blue",eco]
What I want is to get realm results where ALL strings in the attribute "specifications" of Cars is in "preferences".
E.g.: If an instance of Cars.specifications contains ["automatic","suv"]
a result should be returned.
But if an instance of Cars.specifications contained ["automatic,"suv","green"] this instance shouldn't be returned.
The length of preferences can vary.
Thank you very much.
Update:
What i tried is the following:
const query = realm.objects("Cars").filtered('specifications = preferences[0] OR specifications = preferences[1]')
As you see it is an OR operator which is surely wrong and it is hardcoded. Looping with realm really confuses me.
This code will work!
const collection = realm.objects('Cars');
const preferences = ["automatic","suv","blue","eco"];
let queryString = 'ANY ';
for (let i = 0; i < preferences.length; i++) {
if (i === 0) {
queryString += `specifications CONTAINS '${preferences[i]}'`;
}
if (i !== 0 && i + 1 <= preferences.length) {
queryString += ` OR specifications CONTAINS '${preferences[i]}'`;
}
}
const matchedResult = collection.filtered(queryString);
example of function to test if a word is inside an array of word
function inArray(word, array) {
var lgth = array.length;
word = word.toLowerCase();
for (var i = 0; i < lgth; i++) {
array[i] = (array[i]).toLowerCase();
if (array[i] == word) return true;
}
return false;
}
const preferences = ["automatic","suv","blue","eco"];
const specifications = ["automatic","suv"] ;
const specifications2 = ["automatic","suv", "boat"] ;
function test(spec,pref){
for (var i in spec){
if(!inArray(spec[i],pref)){
return false ;
}
}
return true;
}
console.log(test(specifications,preferences));
console.log(test(specifications2,preferences));
https://jsfiddle.net/y1dz2gvu/

PDFBox: Remove text behind image

I am in a requirement to split a pdf into two, one with image and one with text. I dont want to remove the text which are behind an image and it should be the part of the image pdf. I want to extract only the top layered text in the PDF. Can any one help on this?
I already extracted the image and text into two pdfs by looping through pdf operators. I am facing trouble when not to remove the text behind the PDF.
Code for removing text:
PDDocument document = null;
try {
document = PDDocument.load(new File(inputfilePath), password);
PDPageTree allPages = document.getDocumentCatalog().getPages();
for (int i = 0; i < allPages.getCount(); i++) {
PDPage page = (PDPage) allPages.get(i);
PDFStreamParser parser = new PDFStreamParser(page);
parser.parse();
List tokens = parser.getTokens();
List newTokens = new ArrayList();
for (int j = 0; j < tokens.size(); j++) {
Object token = tokens.get(j);
if (token instanceof Operator) {
Operator op = (Operator) token;
if (op.getName().equalsIgnoreCase(
"tj")) {
try {
// remove the one argument to this operator
newTokens.remove(newTokens.size() - 1);
} catch (Exception e) {
e.printStackTrace();
}
continue;
}
// Header doesn't contain versioninfo
}
newTokens.add(token);
}
PDStream newContents = new PDStream(document);
ContentStreamWriter writer = new ContentStreamWriter(newContents.createOutputStream());
writer.writeTokens(newTokens);
// In writeTokens method, I closed the output stream.. This is
// for future reference.. or it will throw stream not closed
// error
newContents.addCompression();
page.setContents(newContents);
if (DEBUG)
System.out.println("Background image pdf creation process");
document.setAllSecurityToBeRemoved(true);
document.save(outputFolder + "/img_" + fileName);
And for removing the images and shades, I used the below code:
for (int j = 0; j < tokens.size(); j++) {
Object token = tokens.get(j);
if (token instanceof Operator) {
Operator op = (Operator) token;
// Text Extraction removing image and shades
if (op.getName().equalsIgnoreCase("do") || op.getName().equalsIgnoreCase("sh")
|| op.getName().equalsIgnoreCase("gs") || op.getName().equalsIgnoreCase("bi")
|| op.getName().equalsIgnoreCase("id") || op.getName().equalsIgnoreCase("ei")
|| op.getName().equalsIgnoreCase("bmc") || op.getName().equalsIgnoreCase("bdc")
|| op.getName().equalsIgnoreCase("emc") || op.getName().equalsIgnoreCase("m")
|| op.getName().equalsIgnoreCase("w")
|| op.getName().equalsIgnoreCase("re")
) {
// remove the one argument to this operator
newTokens.remove(newTokens.size() - 1);
continue;
}
}
newTokens.add(token);
}

Make OCG layer visible when field isn't empty?

Is it possible to check when a field is not empty and if not, make an ocg layer visible?
var ocg = FindOCG("Item 1 Arrow");
if (+event.value === '') {
ocg.state = !ocg.state;
} else {
ocg.state = !ocg.state;
}
Something like this (which doesn't work)!
Put this in the custom format script of the field in question. Replace "Square" with the name of your layer. You can see an example of it working here.
function getOCGByName(cName, nPage) {
var ocg = null;
var ocgArray = this.getOCGs(nPage);
for (var i=0; i < ocgArray.length; i++) {
if (ocgArray[i].name == cName) {
ocg = ocgArray[i];
}
}
return ocg;
}
var field = event.target;
var ocg = getOCGByName("Square", this.pageNum);
if (field.value.length > 0) {
ocg.state = true;
}
else {
ocg.state = false;
}
Note: This will only work in Adobe Acrobat and Reader and a few other viewers that are JavaScript capable.

Pdfsharp - How to determine the page number of a field

I need to draw an image on a page that has a specific form field. Using pdfsharp, given a field name, how do I find the pdf page associated with that field?
Here an improvement with corrections which gives also back the pagenum:
PdfPage GetPageFromField(PdfDocument myDocument, string focusFieldName, out int pageNum)
{
// get the field we're looking for
PdfAcroField currentField = (PdfAcroField)(myDocument.AcroForm.Fields[focusFieldName]);
pageNum = 0;
if (currentField != null)
{
// get the page element
var focusPageReference = (PdfReference)currentField.Elements["/P"];
// loop through our pages to match the reference
foreach (var page in myDocument.Pages)
{
pageNum++;
if (page.Reference == focusPageReference)
{
return page;
}
}
}
// could not find a page for this field
return null;
}
You can access the page reference for the field using the page element of the field object. Then use this reference to match the page in the document.
public PdfPage GetPageFromField( PdfDocument myDocument, string focusFieldName )
{
// get the field we're looking for
PdfTextField currentField = (PdfTextField)( fillablePdf.AcroForm.Fields["MyFocusField"]);
if( currentField != null )
{
// get the page element
var focusPageReference = (PdfReference)currentField.Elements["/P"];
// loop through our pages to match the reference
foreach( var page in myDocument.Pages )
{
if( page.Reference = focusPageReference )
{
return page;
}
}
}
// could not find a page for this field
return null;
}