Search code examples
asp.net-mvctwitter-bootstraprazorbootstrap-datepicker

Can't attach GlyphIcon to Textbox


I'm having real issues trying to get my bootstrap datepicker icon to attach to my textbox. I've read through all documentation and searched for hours to find a solution but nothing seems to work.

This is the closest i've gotten with my markup but the icon seems to align to the right hand side of the screen

<div  id="sandbox-container">DATE
    <div class="input-group date">
        <input type="text" class="form-control"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
    </div>
</div>

Solution

  • It's pretty easy to do with Bootstrap input group and Font Awesome icons:

    Structure

    <label for="xxx">Date</label>
    <div class="input-group">
        <input type="text" class="form-control" id="xxx">
        <div class="input-group-append">
            <span class="input-group-text">
                <i class="fas fa-calendar-alt"></i>
            </span>
        </div>
    </div>
    

    Icon Choices

    I am showing you the free version of Font Awesome Icons. You can use whatever you like to represent the date picker icon. Here is some: https://fontawesome.com/icons?d=gallery&q=calendar&m=free

    Screenshots

    enter image description here

    Demo

    https://jsfiddle.net/davidliang2008/9a20fp3u/37/