0

I'm using OpenMRS, it's an opensource medical records system. OpenMRS has a built-in html editor and I use this mostly in javascripting ang building the forms. In one of my forms,I have a textarea. My client would like his entries(in paragraph or in list) to be indented in the textarea.

Now when you try indenting the paragraph in the textarea then save the changes and preview the form, the paragraph becomes justified instead of retaining the indented lines.

However, if I try indenting the paragraph using ascii code for non-break space by typing   or pressing alt-288, the paragraph becomes indented thus giving me the desired result. Now, the users don't prefer typing or pressing ascii equivalents coz that'll be hassle on their part.

I'm using mostly javascript and jQuery because it's what openmrs supports. If I could somehow bind the non-break space character upon pressing a key then this will work, but I'm at a lost here. How will I do this in javascript or jquery?

David Thomas
  • 249,100
  • 51
  • 377
  • 410
Paul
  • 85
  • 1
  • 5
  • You can create inline code by surrounding the entered characters with backticks `\``, or code-blocks by indenting each line of the code by (at least) four spaces and having a blank line before and after. See the [editing-help page](http://stackoverflow.com/editing-help/) for more advice. – David Thomas Oct 23 '12 at 12:45

1 Answers1

0

One solution which might work for you is to replace leading spaces in the textarea when you process/save or even each time it changes it something like :

ta.value = ta.value.replace (/\n +/, function (m) {
    return '\n' + Array (m.length).join ('&#160');
});

The Array ... constructs creates an array containing length elements then joins with your non-breakspace character effectively creating a string of that many space chars.

Another possibility is to watch for space characters entering the text-area and transforming them. See here : Can I conditionally change the character entered into an input on keypress?

Community
  • 1
  • 1
HBP
  • 15,685
  • 6
  • 28
  • 34