Today I encountered something interesting, It was small but yet to gave me some challenge. In one of the web form we have Dojo text area. What we found while testing if user copy-paste some contents from MS word/excel contents get truncated or even impossible to read.Something like,

But if you just close and re-open the document , everything looks perfect. here it is,

Now what could be easy to implement solution without doing much changes from ground. What I thought lets create one button next to the existing "text Area" field say "click to paste". It will open a dialog box with another "text area" field which will allow to write or paste the contents from various sources.Once done you can click OK and dialog box's contents moved to the original text area which is in read only mode.It could be much simpler if you have just a text field or something to pass via Query String. After little mind-boggling I was able to fix this. Here are the logic.

Lets assume my original text area field name is "Body_1". So, Following code is implemented on "Click to Paste" button (which is mentioned on the top) ,

var childWin;
var pData

if ( document.getElementById('Body_1').value != "" ) {'server/db/form?OpenForm','popup','status=0,toolbar=0,scrollbars=0,resizable=0,width=500,height=145,top=500,left=550')
else {'server/db/form?OpenForm','popup','status=0,toolbar=0,scrollbars=0,resizable=0,width=500,height=145,top=500,left=550')


Next, Lets assume our dialog box's field name is "Body". Here is the code which is written on "onLoad" event of the dialog box to retrieve parent's value ,

document.getElementById("Body").value = window.opener.document.getElementById("Body_1").value

At the end here is the code which will set Child form's field contents to parent ,

var pData= document.forms[0].Body.value
window.opener.document.getElementById('Body_1').value= pData
window.opener.document.getElementById("btnPaste").value="Click to Edit"

Lets see all steps in image ,

Step 1- When form loads ,

Step 2 - Clicked on "Click to paste" to paste the contents ,

step 3 - Last step to edit the text again ,

Simple and easy to use , right :)

Leave a Reply

preload preload preload