Oracle APEX comma alternatives in Text Field - javascript

Im working with Oracle Application Express (APEX). I have a page with a link and a page with a Text Field (in simple terms). When i click on that link, a JavaScript function puts a coordinate to the second page with the Text Field. The coordinates should appear in that Text Field. The point is: They really appear, but only a part of them. I can show you that:
This should appear in the Text Field:
LatLng(48.30247, 16.02837)
But the Text Field shows only this:
LatLng(48.30247
I realised the problem: Apex thinks, that it should stop writing something in a Text Field, when there is a "," (comma). But I need that "," for my Database. So my question: Is there another way to write the comma? Or can I tell Apex to not do anything when a comma appears?

Parameters in an Apex URI are colon separated, but multi-value parameters, such as lists of page items to set, are comma separated. Apex thinks you are trying to set the value of P202_TEXT_FIELD to "LatLng(48.30247" and the value of a second, unspecified page item to ", 16.02837)".
You can escape commas in an Apex URI by enclosing the value in backslashes, ie:
"\"+popup_coord+"\"

Related

Using a Chrome extension to replace characters spanning more than one line in a Facebook status update

I have created a Google Chrome extension to allow users to select text in a component. This works great for most sites. However, Facebook handles its status updates differently. It seems that even though you are filling in what seems to be a single text box, it is actually using a div > div > span > span construct for every single line in this text box. I have no idea why they chose to do this but it makes replacing multiple lines of text much more complex.
Is there a way to select multiple lines (or even contiguous portions of multiple lines) of text in a Facebook status update and replace the data?
The relevant portion of my code looks like this:
function replace_text(language){
let selection = window.getSelection();
string = selection.toString();
/* This section contains code that uses string.replace to replace characters in the string. */
document.execCommand("insertText", false, string);
}
Based on the way my code works now, if I replace text on a single line I have no problems. But, if I replace text that spans multiple lines I end up with a blank unusable input box. Undoubtedly it is because it is removing portions of the html code. How can I fix my code so that the replacement process works properly not only for other sites but also for Facebook?
As of this moment, the one common theme among all status updates (and comments) are that their texts reside within a single or set of span elements with the attribute data-text set to true. So let's target those:
document.querySelectorAll("span[data-text='true']");
For me, I've typed into the status field 3 lines and comment field 1 line of dummy text. So when I execute the above code into the console it returns an array of those four cumulative lines:
>>> (4) [span, span, span, span]
With that array, I can use the Array.prototype.forEach() method to iterate through the spans and replace the innerText:
document.querySelectorAll("span[data-text='true']").forEach(function(element) {
element.innerText = element.innerText.replace('Lorem ipsum','Hello world');
});
However, it is important to note that these changes are being made in the HTML itself and Facebook doesn't store all of its data directly in the HTML. Therefore it can cause undesirable events to occur when you type text into a field, unfocus, change the text in the field, and refocus that field. When you refocus I believe it grabs data of what the text was, before you unfocused that field, from an ulterior source like React's Virtual DOM. To deter it from doing that, the changes either need to be made after clicking the field (real or simulate) or as the user is typing using some sort of MutationObserver (src).

Calculated numbers using javascript not displayed correctly in interactive report

I am pretty new to oracle apex and working on a case for myself to get oracle apex 5 more in control... :-).... hopefully. I have 2 pages: 1 interactive report on a table and 1 for a form to add and modify
records. In the form there are 4 fields: P12_VAT_PERC, P12_VAT_AMOUNT, P12_NET_AMOUNT and P12_TOT_AMOUNT (all 4 database fields, type number). I have created one dynamic action on event lose focus on one of the 4 field items mentioned above. The event is fired when true with 2 actions. Action 1 is set value on P12_VAT_AMOUNT, set type javascript expression:
($v('P12_VAT_PERC') / 100) * $v('P12_NET_AMOUNT');
Action 2 set value on P12_TOT_AMOUNT, set type javascript expression:
parseFloat($v('P12_NET_AMOUNT'))+parseFloat(($v('P12_VAT_PERC') / 100) * $v('P12_NET_AMOUNT'));
In the form it works. Values for P12_VAT_AMOUNT and P12_TOT_AMOUNT are calculated and displayed correctly as number (with the decimals if applicable) once calculated after losing focus on one of the 4 fields. But when page is submitted the value is not displayed correctly in the report and also not correct stored in database. I.e. before submitting P12_VAT_AMOUNT is calculated and displayed as 25.919999999999998. After submitting in the report it is displayed as 25919999999999998. I am missing the decimal sign. Also in the database it is stored like 2.592E16.
When I open this record in the form again for editing, it is initially displayed as in the report like 25919999999999998. When changing i.e. P12_VAT_PERC and change the focus, the field is caclulated correctly and displayed again with decimal sign on correct place. After submit it goes wrong again. To solve this, I found out that having the dynamic action also fired on page load (I enabled this option), this part of the problem was solved. Values are displayed correctly in form by javascript, but the wrong value seems to be stored in the database and not correctly displayed in the interactive report.
Same behavior for P12_TOT_AMOUNT.
I have the idea that APEX is using the dot as decimal character but the regional settings (Dutch) of the machine on which the browser is running are set to comma. When I enter a comma as decimal sign, the calculated fields are showing as NaN.
What do i do wrong? Hope someone can help me and put me in de direction where to find the solution.
The real problem that javascript is using always a dot as decimal separator and my locale is set to decimal. I will now focus on that problem. It has nothing to do with Apex.

How to avoid escape character while retrieving from textbox/textarea through jquery?

here i'm copying the contents from webpage and pasting the contents in form fields like textarea. while retrieving the form contents, escape characters are also coming along which is breaking the functionality. how to avoid the escape characters and retrieve only the given text. The escape characters are not visible in the form fields, but its visible in json.
the above 1st image is entered text and second image is retrived in json. Help me out in this
Thanks.
Try to remove the line breaks with this line of code:
text = text.replace(/(\n|\r)/gm,"");
Cf: How to remove all line breaks from a string?

How do I bind a non-breakspace(alt-288 or  ) upon pressing the space bar in javascript?

I'm using OpenMRS, it's an opensource medical records system. OpenMRS has a built-in html editor and I use this mostly in javascripting ang building the forms. In one of my forms,I have a textarea. My client would like his entries(in paragraph or in list) to be indented in the textarea.
Now when you try indenting the paragraph in the textarea then save the changes and preview the form, the paragraph becomes justified instead of retaining the indented lines.
However, if I try indenting the paragraph using ascii code for non-break space by typing   or pressing alt-288, the paragraph becomes indented thus giving me the desired result. Now, the users don't prefer typing or pressing ascii equivalents coz that'll be hassle on their part.
I'm using mostly javascript and jQuery because it's what openmrs supports. If I could somehow bind the non-break space character upon pressing a key then this will work, but I'm at a lost here. How will I do this in javascript or jquery?
One solution which might work for you is to replace leading spaces in the textarea when you process/save or even each time it changes it something like :
ta.value = ta.value.replace (/\n +/, function (m) {
return '\n' + Array (m.length).join ('&#160');
});
The Array ... constructs creates an array containing length elements then joins with your non-breakspace character effectively creating a string of that many space chars.
Another possibility is to watch for space characters entering the text-area and transforming them. See here : Can I conditionally change the character entered into an input on keypress?

Determine visible characters to be highlighted using html source

I'm using TinyMCE to let users edit and format text, output is html code.
The html is then sent to the server and is pushed to other clients that can follow the edit progress on a webpage, the html is inserted into a div so users can see the format but they are not able to edit.
Now I want the cursor position and any selection the user makes in the editor to show up on the readonly page using highlight(background color) if selected or inserting an empty span with a black border between characters to imitate the cursor position.
I made an attempt using
editor.tinymce().selection.getRng()
which gives me the start and end position of what the user sees(formatting characters are not counted)
Then I traversed the DOM and counted the characters in every text element wrapping the ones selected with a highlight span. This resulted in messy code but worked pretty well until I hit a non ascii or encoded character in the textblock.
Example html
<p>abc <b>de</b>fg</p>
looks like this to the user
abc defg
Say user selected character c to d (selection covers c, a blank, first half of the bold tag and d),
tinymce will return range start:2 end:5
but the actual characters behind would be start:5 end:16.
Just wrapping the text from char 5 to 16 in a highlight span will result in bad html.
Checking for words starting with & and ending with ; and adding number of positions will turn into a mess. There has to be a simpler way
How do I calculate how many "visible" characters a set of html character will turn into?
Or maybe you would attack the problem in another way
Thanks
PS 1
I've looked into the various jquery highlight plugins but they seem to highlight based on a search string. Those does not work in the case user selects one character and that character exists several times, they will then highlight all occurences.
I've tackled this problem in my Rangy library: the TextRange module concerns itself with the text the user sees. It sounds like you need the selectCharacters() and toCharacterRange() methods of Rangy's Range objects.

Categories