Forum


18:32

17/12/2008

Hi,
I have a column called "Comments ". I set it as "TEXTAREA" on the edit form. I can use "Enter" key to do a new line in the input box. And the new line "\\n" can be saved in the database. But when I open the edit form again, the line break disappear. How to show the line break in the text area input box again? I am thinking of doing something using onInitializeForm function:
onInitializeForm :
function (formid) {
//replace "\\n" with the html code <br/>;
}
Is this doable? can you give me some example codes?
Thanks!
Maggie
05:25

Moderators
30/10/2007

Hello,
onInitialize form fires only one time. Try with beforeShowForm for that textarea field
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
07:59

17/12/2008

Hello,
I figured out how to get the form field value. but I can't make the line break work. My codes are as below:
beforeShowForm : function(formid){
//get comments (text area field) value;
var comments= $("#comments",formid).val() ;
//replacement
var newComments = comments.replace(/\\n/g, "<br/>");
//set field with new value
$("#comments",formid).val(newComments);
}
For example, I want the field show in sevral lines:
firstline
secondline
thirdline
but it shows as firstline<br/> secondline<br/> thirdline
How to convert the <br/> to new lines?
I know I can use "
<![CDATA[]]>
" for the grid cell value, but it does not work for the edit form field.
Thanks, Maggie
02:36

Moderators
30/10/2007

Hello,
It is really difficult to play with this, but maybe you will need to call ajax in beforeShowForm to obtain that field from db.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
10:42

22/06/2009

Maggie, I'd be interested to know if you got anywhere with this as I am just starting to look at the same problem. I'm using inline editing. So far I've made a change to grid.inlinedit.js and allowed enter to be used in textareas without the row saving. But now I'm getting the same line break problem. The data is saved correctly, ie - it preserves the line break, but I don't know how to output the lline break to the textarea when editing.
05:36

22/06/2009

Right, I am getting somewhere with this problem now but am stuck again, so I'm hoping some kind soul could offer some advice.
In my function which returns (JSON format) data from the server, I'm doing a replace on CHR(10) and returning <BR> instead. This has the desired effect of breaking up my text in cells in the grid. Problem 1 solved.
In my call to editRow in my onSelectRow event, I'm passing a function name to the oneditfunc parameter. In this function I'm replacing <BR> with \\n. This has the desired effect of putting line breaks into my editable text area when the row is clicked. Problem 2 solved 🙂
My remaining problem is thus: when I edit a cell and put carriage returns in the text and hit return, the row is saved. Looking in my data, I can see that it has saved with a chr(10). So far so good. However, the grid doesn't refresh after a save, and the grid replaces any carriage returns with spaces. ie - in the GUI, it has now lost me my nice line breaks. So my question is - what is the best way to have the grid preserve these line breaks once they have been edited?
Thanks in advance.
04:26

22/06/2009

ok ...
I've solved my final problem by editing grid.inlinedit.js. After line 94:
tmp[nm]= !$t.p.autoencode ? $("input, textarea",this).val() : htmlEncode($("input, textarea",this).val());
I've added:
tmp[nm]=tmp[nm].replace(/\\n/g,'<BR>');
This replaces the javascript \\n line breaks with a <BR> and allow line breaks to show correctly in cells when they are not being edited.
Most Users Ever Online: 715
Currently Online:
43 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66