Search code examples
javascriptjquerymomentjscombodate

Combodate/moment.js DD-MM-YYYY dropdown - style issue


I am using combodate and moment.js to have a dropdown DD-MM-YYYY. It's perfectly functional and inserts data into my tables but only shows as unstyled small dropdown boxes unlike the demo.

I have tried styling it in bootstrap and css but it changes nothing and only seems to create issues. I've tried on multiple browsers with the same result and no errors. I have tested my jQuery and its working fine. I am running this locally, My code is below:

$(document).ready(function() {
  $(function() {
    $('#date').combodate();
  });
});

<script src="./js/combodate.js"></script>
<script src="./js/moment.min.js"></script>
<input type="btn btn-drowpdown" method="post" name="date" id="date" data-format="YYYY-MM-DD" data-template="D-MMM-YYYY" value="09-01-2013">

I am still new to coding especially javascript/jQuery and its probably something very small I've overlooked. Any help is greatly appreciated.


Solution

  • I have got it working, but had to come up with a different approach.

    I copied the sample code on JSFiddle from Combodate Github's page and altered it a bit.

    <h3>Combodate</h3>
    <div class="form-inline">
        <div style="margin: 50px;" class="input-group">
            <input type="text" id="date" data-format="DD-MM-YYYY" data-template="D MMM YYYY" />
        </div>
    </div>
    

    I added a <div> layer to accommodate form-inline and input-group style classes for this component, otherwise the three generated combos would be shown on separate lines.

    $(function(){
        $('#date').combodate({
              value: new Date(),
              minYear: 2012,
              maxYear: moment().format('YYYY'),
              customClass: 'form-control'
        });    
    });
    

    And then I added customClass to Combodate's init properties to style all three combos accordingly.

    I don't know what OP is expecting as result, then I tried to guess it. Hope it helps.

    The sample is published in JSFiddle: https://jsfiddle.net/flaviocysne/4g5p46zd/