I have this inside a JSF page,
<textarea id="textarea" rows="4" cols="50"
onKeyPress="validate(event)" onPaste="validatepaste(event)"></textarea>
The reason I am not using <h:inputTextarea>
is because onPaste
attribute seems to be missing with this JSF tag.
When I debug my code in Google Chrome, I am surprised to find onPaste
attribute is not there,
The rendered html code is,
<textarea id="j_id_2:textarea" name="j_id_2:textarea"
onkeypress="return validate(event)" cols="15" rows="5"></textarea>
Since JSF is nothing but a HTML code generator, I failed to understand what it does to onPaste attribute and why is it not supported?
Secondly. how will i achieve value binding on this html textarea
?
EDIT:
Since onkeyup is supported and is standardised
Why does then onkeyup functionality breaks when working with <hinputTextarea>
?
I am not able to achieve the same thing which I am with html textarea field.
The following function prevents alphabatical text to be replaced by "" as soon as the user enters manually by keyboard input or by copy pasting. Here's the snippet:
function validate(e) {
console.log(e)
var invalidcharacters = /[^0-9]/gi
var phn = document.getElementById('textarea');
if (invalidcharacters.test(phn.value)) {
//e.value = e.value.replace(invalidcharacters, "");
console.log("REPLACING");
newstring = phn.value.replace(invalidcharacters, "");
phn.value = newstring
}
}
It works fine with normal html as shown below. Here the jsfiddle
<textarea id="textarea" rows="4" cols="50" onkeyup="validate(event)"></textarea>
The same functionality is not achievable with
<h:inputTextarea value="#{myBean.myValue}" id="compTextArea"
onkeyup="validate(event)"></hinputTextarea>
and replacing this line var phn = document.getElementById('textarea');
with document.getElementById('compTextArea');
in the js file method.
Anyreasons why this seems strange?