user3356094
user3356094

Reputation:

HTML/JS - Bootstrap Datepicker

In the past the systems I have built have used the jQuery datepicker and it worked great. Recently I decided to move to using twitter bootstrap for my designs and quickly learned that it doesn't like the jQuery UI.

I'm trying to get http://www.eyecon.ro/bootstrap-datepicker/ working at the moment.

I've viewed all the similar questions and their solutions, but cannot seem to find any that directly apply to my situation.

The JavaScript:

<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link rel="icon" type="image/ico" href="../images/favicon.ico">
<script type="text/javascript" src="js/tinybox.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="js/bootstrap-datepicker.js"></script>

<script>
    $('#date').datepicker();
    function delete(id)  
        {
        var r=confirm("Are you sure you want to delete?")
            if (r==true)
            {
                location.href = "delete.php?id=" + id;
            }
        }
    function single(id)
        {
            TINY.box.show({iframe:'../view.php?id=' + id,boxid:'frameless',width:550,height:170,fixed:false,maskid:'bluemask',maskopacity:40,closejs:function(){closeJS()}})
        }
</script>

The html:

<input name="date" class="src_date" type="textarea" placeholder="DD-MM-YYYY" id="date" required>

I have also tried with the JS:

$(function() {
    $("#date").datepicker({dateFormat: 'dd-mm-yyyy'});
});

Upvotes: 2

Views: 846

Answers (3)

d.abyss
d.abyss

Reputation: 212

This issue is often the result of a JS conflict, where another plugin is causing the $ variable to behave abnormally. To get around this just wrap your function with jQuery:

$('#date').datepicker();

=>

jQuery(function($){
    $("#date").datepicker({format: 'dd-mm-yyyy'});
});

also your dateFormat parameters are for jQuery UI, for bootstrap datepicker just use format as I have used in the above example.

Upvotes: 2

Rohan Kumar
Rohan Kumar

Reputation: 40639

Load tinybox after jquery and check you have downloaded datepicker and tinybox js like,

Otherwise try this,

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://sandbox.scriptiny.com/tinybox2/tinybox.js"></script>
<script src="http://www.eyecon.ro/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script>
$(function() {
   $("#date").datepicker({dateFormat: 'dd-mm-yyyy'});
});
</script>

Live Demo

Upvotes: 0

Jai
Jai

Reputation: 74738

As if this is not working:

$(function() {
   $("#date").datepicker({dateFormat: 'dd-mm-yyyy'});
});

then it seems to be that you have to load your jQuery library first then other libs:

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/tinybox.js"></script>
<script src="js/bootstrap-datepicker.js"></script>

Upvotes: 0

Related Questions