Issue Summary: Whenever we paste the content in the multiline text field, sometimes it works and sometimes it won't. The reason for this behavior is if the length of content is greater than the length of allowable content (characters) in that field then it won't work else it would work.
Expected Result: Whenever we paste the content it should paste content in the field. If the length of content is greater than the restricted length then it should paste only that limited content. For Example, If our length of content is 3k and we can put only 2k content's length then it should paste the content to 2k characters.
But how we can fix this issue. I don't think there is any OOB way to fix it or maybe in the future MS team will fix this issue. But as of now, I have a custom way to fix it. If anyone has any idea then please drop your comments.
We can fix this issue by using the below code.
$("#FIELD_NAME").bind("paste", function(e) {
var pastedData = e.originalEvent.clipboardData.getData('text');
// Put limit of field. Here I used 2k.
pastedData = pastedData.slice(0,2000);
$("#FIELD_NAME").val(pastedData);
});
Algo of the code is:
- Catch the paste event.
- Get the content and take the content to restricted length i.e 2k in my case.
- And put that content in the field.
Keep learning, Keep Growing, Keep sharing !!!
No comments:
Post a Comment