Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Edit Form Text Area New Line
02/06/2009
18:32
Avatar
maggie
Member
Members
Forum Posts: 49
Member Since:
17/12/2008
sp_UserOfflineSmall Offline

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

04/06/2009
05:25
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

05/06/2009
17:22
Avatar
maggie
Member
Members
Forum Posts: 49
Member Since:
17/12/2008
sp_UserOfflineSmall Offline

Hello,

How to get the value of a field and do the change?

 

I tired this:

beforeShowForm : function(formid){

   alert ("field value: " + $("#Comments",formid).value);

},

But it does not work.

Can you give me an example?

Thanks,

Maggie

06/06/2009
07:59
Avatar
maggie
Member
Members
Forum Posts: 49
Member Since:
17/12/2008
sp_UserOfflineSmall Offline

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

11/06/2009
09:13
Avatar
maggie
Member
Members
Forum Posts: 49
Member Since:
17/12/2008
sp_UserOfflineSmall Offline

Hello,

Anyone knows how to preserve line break in the form text area?

Thanks! Maggie

12/06/2009
02:36
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

23/06/2009
10:42
Avatar
JaySab
Member
Members
Forum Posts: 10
Member Since:
22/06/2009
sp_UserOfflineSmall Offline

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.

30/06/2009
05:36
Avatar
JaySab
Member
Members
Forum Posts: 10
Member Since:
22/06/2009
sp_UserOfflineSmall Offline

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.

01/07/2009
04:26
Avatar
JaySab
Member
Members
Forum Posts: 10
Member Since:
22/06/2009
sp_UserOfflineSmall Offline

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.

26/04/2010
17:20
Avatar
phazzy
Member
Members
Forum Posts: 4
Member Since:
16/03/2009
sp_UserOfflineSmall Offline

Thanks for the solution!

I was replacing "\n" with &#10 after getting data from the server, and it was working perfectly in Firefox even when editing with textarea. But because of the JQuery .html() function behavior it was not working in IE at all. Your solution solved it 🙂

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information