Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all options of jquery datepicker to instanciate new datepicker with same options?

How to get all options of jquery datepicker to instanciate new datepicker with same options?

I want clone a table which contains 2 datepickers with different options. You can see here an example : http://jsfiddle.net/qwZ5x/4/

<div class="clonable">
<table><tr><td>
<input type="text" id="datepicker" />

<script>
    jQuery(document).ready(function() {
        jQuery("#datepicker").datepicker({
            showOn: "both",
            buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif"
        });
    });
</script></td><td>
<input type="text" id="datepicker2" />
<script>
    jQuery(document).ready(function() {
        jQuery("#datepicker2").datepicker();
    });
</script>
    </td></tr></table>
</div>
<a href="javascript:void(0);" id="clone">Clone</a>
var id = 0;
jQuery("#clone").on("click", function () {

var clonable = jQuery(".clonable:first").clone(true, true);
jQuery(clonable).find("input").each(function () {
    jQuery(this).attr("id", jQuery(this).attr("id") + "_" + id);

    jQuery(this).siblings('.ui-datepicker-trigger,.ui-datepicker-apply').remove();

    jQuery(this).removeClass('hasDatepicker');
    jQuery(this).datepicker({
        showOn: "both",
        buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif"
    });
});

jQuery(clonable).insertBefore("#clone");
id = id + 1;
});

How can i set all options to cloned datepicker without set option one by one?

Thank you very much.

like image 611
Franck S Avatar asked Jul 18 '13 15:07

Franck S


1 Answers

You can get the options of the existing datepicker using this:

var options = jquery('#datepicker').datepicker('option', 'all');

to get one specific option, for example the numberOfMonths:

var numberOfMonths = jquery('#datepicker').datepicker('option', 'numberOfMonths');
like image 56
Travesty3 Avatar answered Sep 28 '22 06:09

Travesty3