user1761176
user1761176

Reputation: 103

datepicker not working into new tabs

When I click. Datepicker not working into new tabs
This is code

<script>
var tabCounter = 2,
    tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>";
var tabs = $( "#tabs" ).tabs();
var tabContentHtml = $("#tabs-1").html();

Create datepicker. Work into tab1. Not work into tab2

$( ".rush" ).datepicker();

Add new tabs when click button

$("#add_tab").click(function(){
        addTab();
});
function addTab() {
        var label = "Tab " + tabCounter,
            id = "tabs-" + tabCounter,
            li = $( tabTemplate.replace( /#\{href\}/g, "#" + id ).replace( /#\{label\}/g, label ) );

        tabs.find( ".ui-tabs-nav" ).append( li );
        tabs.append( "<div id='" + id + "'><p>" + tabContentHtml + "</p></div>" );
        tabs.tabs( "refresh" );
        tabCounter++;
    }
</script>

Code html

<div id="tabs">
<ul>
    <li><a href="#tabs-1">Nunc tincidunt</a> <span class="ui-icon ui-icon-close">Remove Tab</span></li>
</ul>
<div id="tabs-1">
    <input type="text" class="rush" />
</div>
</div>
<button id="add_tab">Add Tab</button>

Upvotes: 1

Views: 1935

Answers (2)

Fseee
Fseee

Reputation: 2631

You have to call datepicker after creating the new tab:

$("#add_tab").click(function(){
    addTab();
    $( ".rush" ).datepicker(); //or your new datepicker id
});

Upvotes: 0

twoleggedhorse
twoleggedhorse

Reputation: 5048

The reason it's not working is because the datepicker stuff is done when the page is loaded. When you add a new tab, the datepicker is not being created, have a look at the previous post:

Making datepicker live - JQuery

Upvotes: 1

Related Questions