Word Wrap in Drop Down box

Discussion in 'Programming' started by Deserex, Oct 24, 2008.

  1. #1
    All: I have a drop down box on a cfform that has very long lines of data. Due to the nature of the data, I can not shorten the amount of characters in the SQL table. I have tried to use the Wrap function in my output, but it is cutting off anything after the limit I gave it. It should be wrapping to the next line. Can anyone help me with this? Here is part of my code.

    <td>
    <select name="HAZ_MAT_NME" size="1" class="smallbold" onBlur="setSelectedIndex(this)" onKeyDown="return setSelectedIndex(this)">

    <option value="" selected></option>
    <cfoutput query="hazmatnme">
    <cfset HazWrap=#hazmatnme.HAZ_MAT_NME#>
    <option value="#HazWrap#">#Wrap(HazWrap, 25, False)#</option>
    </cfoutput>
    </select>
    </td>

    Thanks!
     
    Deserex, Oct 24, 2008 IP
  2. robhustle

    robhustle Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Would truncating the data after a certain length be a solution for you? Or do you have to display it all and wrap it?
     
    robhustle, Oct 24, 2008 IP
  3. Deserex

    Deserex Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It needs to be wrapped. From what I've been reading it's really not possible. I've been told even if you do "wrap" the text, it does not indent the 2nd line which makes the dropdown hard to read.
     
    Deserex, Oct 28, 2008 IP
  4. robhustle

    robhustle Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Two ideas:

    1. Break the single option into multiple options with the same value. Optionally indent it and add a divider. So:

    <option value="1">Some Long Text</option>

    Becomes:

    <option value="1">Some</option>
    <option value="1">&nbsp;&nbsp;&nbsp; Long</option>
    <option value="1">&nbsp;&nbsp;&nbsp; Text</option>
    <option>-----------------</option>

    2. You can implement a custom form element in Ajax or AS3.
     
    robhustle, Oct 28, 2008 IP
  5. Deserex

    Deserex Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the great idea! We used something similar thanks to you and trimmed it. It works!!! Your the bestest :p
     
    Deserex, Nov 11, 2008 IP
  6. robhustle

    robhustle Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Glad it worked. Woot!
     
    robhustle, Nov 11, 2008 IP
  7. Deserex

    Deserex Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This is what I used...

    <cfif #len(query.name)# gt 75>
    <option value="#query.name#">#Left(query.name, 75)#</option>
    <option value="#query.name#">#Right(query.name, 75)#</option>
    <option value="">-------------------</option>
    <cfelse>
    <option value="#query.name#">#query.name#</option>
    </cfif>

    Any idea on how to get it to break it at the last space in the text? Right now it's taking the left 75 charachters and the right 75 characters and putting it on two lines. The problem is if it is less than 150 characters in the line it is duplicating data and breaking words. :confused:
     
    Deserex, Nov 13, 2008 IP
  8. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Check cflib.org. IIRC they have a function for breaking on whole words. Something like fullLeft()..
     
    cfStarlight, Nov 13, 2008 IP