Referencing a Bootstrap icon within jQuery datepic

2019-05-03 06:11发布

What value should I be using for the jQuery datepicker buttonImage attribute?

I would like to use the Bootstrap calendar icon with the jQuery datepicker. I can use the icon image in the html page when referenced like this:

<i class=icon-calendar></i>

When I use the angular-ui wrapper ui-date to wrap the jQuery datepicker:

    <div class="control-group">
        <label class="control-label" for="startDate">Start Date</label>
        <div class="controls">
            <input class="span2" id="startDate" type="text"
                   data-ng-model="formModel.startDate" 
                   data-ui-date="formModel.datePickerOptions"
                   data-ng-change="formModel.setAdjustmentDate()"
                   required >
        </div>
    </div>

with the controller defining the datepicker options as:

formModel.datePickerOptions = {
     dateFormat: 'yy-M-dd'
    ,changeMonth: true
    ,changeYear: true
    ,buttonImage: '<i class=icon-calendar></i>'
    ,buttonImageOnly: true
    ,showOn: "button"
};

What value should I actually be inserting for the buttonImage?

The datepicker is expecting an image url something like this { buttonImage: "/images/datepicker.gif" }.

3条回答
Deceive 欺骗
2楼-- · 2019-05-03 06:39

You can arrange the icon in following way and than assign jquery to them.

jsfiddle Jsfiddle datepicker

<div data-date-format="dd-mm-yyyy" data-date="19-02-2013" id="datepick"class="input-append date">
<input type="text" readonly="" value="19-02-2013" size="16" class="span2">  
    <span class="add-on"><i class="icon-calendar"></i></span>

<div class="control-group">
<label class="control-label" for="inputDatepicker">Datepicker</label>
<div class="controls">
    <div class="input-prepend">
        <button class="btn" type="button" id="datepick"><i class="icon-calendar"></i>
        </button>
        <input class="span2" id="appendedInputButton" type="text">
    </div>
</div>

查看更多
相关推荐>>
3楼-- · 2019-05-03 06:42

I know this is a late reply, but I found this article which does the same thing and with ease:

http://jasenhk.wordpress.com/2013/03/09/jquery-datepicker-with-bootstrap-icon/

and jsFiddle from the same article: http://jsfiddle.net/jasenhk/B2txR/

The author suggests using the "for" attribute to match the id of the input control.

The fiddle has a simple appended input control:

<div class="form-horizontal">
    <div class="control-group">
        <label for="date-picker-2" class="control-label">B</label>
        <div class="controls">
            <div class="input-append">
                <input id="date-picker-2" type="text" class="date-picker" />
                <label for="date-picker-2" class="add-on"><i class="icon-calendar"></i>
                </label>
            </div>
        </div>
    </div>
</div>

And then we just need to call datepicker as:

$(".date-picker").datepicker();
查看更多
Root(大扎)
4楼-- · 2019-05-03 06:59

For what you are doing, rather than messing with the buttonImage attribute, I recommend you just put the icon markup into the buttonText value

.value('ui.config', {
    date: {
        dateFormat : 'mm-dd-yy',
        minDate    : '+1d',
        showOn     : 'button',
        buttonText : '<i class="icon-calendar"></i>'
    }
})
查看更多
登录 后发表回答