0

I have a table cell in which there is list of aircraft registration numbers in the format 'X-XXXX'. The width of the table cell means that the list gets word-wrapped on the hyphen, like so:

G-ABCD,G-
EFGH,G-
IJKL

What I'd like to happen is that the line-break is forced on the comma:

G-ABCD,
G-EFGH,
G-IJKL

However, I cannot insert any special characters. This is because when the form is submitted, the data in the table is submitted as JSON format which is then json_decoded in PHP. Any special characters in the comma separated string then stops the json_decode function from turning it into an array.

So I really need a solution that does not alter the list in anyway? Sounds impossible...

James Ludlow
  • 430
  • 1
  • 4
  • 22
  • Would using the non-breaking hyphen `‑` be a solution here ? – Laurent S. Jan 22 '15 at 10:37
  • ...and shouldn't each tail number be in a separate cell? – Paulie_D Jan 22 '15 at 10:37
  • Each row is for a part - then this cell lists all the aircraft that part is used on, so separate cells isn't an option. – James Ludlow Jan 22 '15 at 10:42
  • The problem I have with using special characters like ‑ is that I'd need to insert them when the datatables.editor does the .join. If I use a special character, when I do the json_encode I get field:"G-ABCD,‑,"G-EFGH‑," Where as I really need field:["G-ABCD","G-EFGH"] – James Ludlow Jan 22 '15 at 10:44
  • 1
    Can you affect the width of the cell / column. If you shrink it down it will force the line break after the comma anyway, wouldn't it? – Paulie_D Jan 22 '15 at 10:52
  • I seem to have got it working with a combination of padding and this answer: http://stackoverflow.com/questions/14190420/firefox-word-break-breaks-short-words-at-random-points/14191114#14191114 However it seems a bit hacky. For instance if the number of characters in the registration number ever increases this fix won't work. Not sure there is a better solution other than to add another column in the datatable for display purposes only. – James Ludlow Jan 22 '15 at 11:14

1 Answers1

0

To force a line break, use the <br> tag. If you cannot have it in the HTML markup, add it with JavaScript.

This answers the question asked. The actual problem is probably different. You need to post more code and ask differently to have it solved. What is the context, what are the constraints, and what do you actually want to do? (From the discussion in the comments, it seems that you rather want to prevent line breaks after hyphens than force any breaks.)

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390