Replace commas with dots
Replace commas with dots
paintitblack
Posts: 60Questions: 20Answers: 0
Hi,
I have some fields where I use "float" numbers (e.g. 2.81) and when I copy values from a source the numbers will be provided with a comma (like 2,81).
Is there a solution to replace the comma while/after paste it into the field?
Thanks in advance
Patrick
This question has accepted answers - jump to:
This discussion has been closed.
Answers
You could listen for the
paste
event on the input element in question (assuming this is in Editor, you can get the input element usingfield().input()
). Then modify the value as required.Allan
That sounds interesting and I created this example:
<input type="text" onpaste="myFunction(this.value)" id="myText" value="Paste something in here">
function myFunction(p1) { // alert(p1); alert( document.getElementById("myText").value ); }But unfortunately it gave me only the orginal value and not the pasted value back.
Do you have any idea and also how to combine it with datatables?
Patrick
You might have to add a short
setTimeout
to let the value be set and then read the value and you can modify it that way. Even asetTimeout
of 0mS might be enough.Allan
Cool this try works pretty well:
function myFunction(p1) { alert(p1); }<input type="text" placeholder="Paste text" onPaste="var e=this; setTimeout(function(){myFunction(e.value);}, 0);">
But how can I call the function with datatables? Is it possible to add it to single fields (to use it e.g. just for 2 of 8 fields)
Patrick
I tried the below code and it seems to work.
Not sure this is the best way (I'm not the most proficient at JS :-). Just change the
'name'
to the name of the Editor field of interest.Kevin
Looks good to me .
Allan
I really love datatables, but you guys are really awesome. Your code works pretty good :-)
Is it possible to use the function for two or more fields like this:
Cheers,
Patrick
There are a few ways to do it, but I'm afraid that isn't one of them!
field()
doesn't take an array option.You could use
jQuery().add()
with the input elements from the two fields to create a single jQuery instance that contains both nodes.Or save the function into a variable and pass that variable in as the callback for the event handler for both elements.
Allan
ok, but I have only two fields where I need it that's why I will use this way:
Thank you very much for your support.
Patrick
Code reuse:
Allan
As always it works pretty well. Thank you very much for your support. I really love datatables :-)