When I Add Dynamic Field jQuery datepicket Is Not Wotking
I'm using jQuery datepicker, when i add dynamic fields, datepicker is not working on dynamically added fields...
Thanks In Advance.
My HTML Date Type Field:
<td><input type="text" name="myDob" class="form-control form-control-sm datepicker" placeholder="Date of Birth: "></td>
My DatePicker jQuery:
// We don't want the val method to include placehoder value, so removing it here.
var $valFn = $.fn.val;
$.fn.extend({
val: function() {
var valCatch = $valFn.apply(this, arguments);
var placeholder = $(this).attr("placeholder");
// To check this val is called to set value and the val is for datePicker element
if (!arguments.length && this.hasClass('hasDatepicker')) {
if (valCatch.indexOf(placeholder) != -1) {
return valCatch.replace(placeholder, "");
}
}
return valCatch;
}
});
// Insert placeholder as prefix in the value, when user makes a change.
$(".datepicker").datepicker({
onSelect: function(arg) {
$(this).val($(this).attr("placeholder") + arg);
}
});
Here is my Dynamic Add Fields jQuery:
$(document).ready(function() {
//group add limit
var maxGroup = 10;
//add more fields group
$(".addMore").click(function() {
if ($('body').find('.fieldGroup').length < maxGroup) {
var fieldHTML = '<table class="table table-bordered fieldGroup">' + $(".fieldGroupCopy").html() + '</table>';
$('body').find('.fieldGroup:last').after(fieldHTML);
} else {
alert('Maximum ' + maxGroup + ' groups are allowed.');
}
});
//remove fields group
$("body").on("click", ".remove", function() {
$(this).parents(".fieldGroup").remove();
});
});
Updated Image:
jquery html
add a comment |
I'm using jQuery datepicker, when i add dynamic fields, datepicker is not working on dynamically added fields...
Thanks In Advance.
My HTML Date Type Field:
<td><input type="text" name="myDob" class="form-control form-control-sm datepicker" placeholder="Date of Birth: "></td>
My DatePicker jQuery:
// We don't want the val method to include placehoder value, so removing it here.
var $valFn = $.fn.val;
$.fn.extend({
val: function() {
var valCatch = $valFn.apply(this, arguments);
var placeholder = $(this).attr("placeholder");
// To check this val is called to set value and the val is for datePicker element
if (!arguments.length && this.hasClass('hasDatepicker')) {
if (valCatch.indexOf(placeholder) != -1) {
return valCatch.replace(placeholder, "");
}
}
return valCatch;
}
});
// Insert placeholder as prefix in the value, when user makes a change.
$(".datepicker").datepicker({
onSelect: function(arg) {
$(this).val($(this).attr("placeholder") + arg);
}
});
Here is my Dynamic Add Fields jQuery:
$(document).ready(function() {
//group add limit
var maxGroup = 10;
//add more fields group
$(".addMore").click(function() {
if ($('body').find('.fieldGroup').length < maxGroup) {
var fieldHTML = '<table class="table table-bordered fieldGroup">' + $(".fieldGroupCopy").html() + '</table>';
$('body').find('.fieldGroup:last').after(fieldHTML);
} else {
alert('Maximum ' + maxGroup + ' groups are allowed.');
}
});
//remove fields group
$("body").on("click", ".remove", function() {
$(this).parents(".fieldGroup").remove();
});
});
Updated Image:
jquery html
add a comment |
I'm using jQuery datepicker, when i add dynamic fields, datepicker is not working on dynamically added fields...
Thanks In Advance.
My HTML Date Type Field:
<td><input type="text" name="myDob" class="form-control form-control-sm datepicker" placeholder="Date of Birth: "></td>
My DatePicker jQuery:
// We don't want the val method to include placehoder value, so removing it here.
var $valFn = $.fn.val;
$.fn.extend({
val: function() {
var valCatch = $valFn.apply(this, arguments);
var placeholder = $(this).attr("placeholder");
// To check this val is called to set value and the val is for datePicker element
if (!arguments.length && this.hasClass('hasDatepicker')) {
if (valCatch.indexOf(placeholder) != -1) {
return valCatch.replace(placeholder, "");
}
}
return valCatch;
}
});
// Insert placeholder as prefix in the value, when user makes a change.
$(".datepicker").datepicker({
onSelect: function(arg) {
$(this).val($(this).attr("placeholder") + arg);
}
});
Here is my Dynamic Add Fields jQuery:
$(document).ready(function() {
//group add limit
var maxGroup = 10;
//add more fields group
$(".addMore").click(function() {
if ($('body').find('.fieldGroup').length < maxGroup) {
var fieldHTML = '<table class="table table-bordered fieldGroup">' + $(".fieldGroupCopy").html() + '</table>';
$('body').find('.fieldGroup:last').after(fieldHTML);
} else {
alert('Maximum ' + maxGroup + ' groups are allowed.');
}
});
//remove fields group
$("body").on("click", ".remove", function() {
$(this).parents(".fieldGroup").remove();
});
});
Updated Image:
jquery html
I'm using jQuery datepicker, when i add dynamic fields, datepicker is not working on dynamically added fields...
Thanks In Advance.
My HTML Date Type Field:
<td><input type="text" name="myDob" class="form-control form-control-sm datepicker" placeholder="Date of Birth: "></td>
My DatePicker jQuery:
// We don't want the val method to include placehoder value, so removing it here.
var $valFn = $.fn.val;
$.fn.extend({
val: function() {
var valCatch = $valFn.apply(this, arguments);
var placeholder = $(this).attr("placeholder");
// To check this val is called to set value and the val is for datePicker element
if (!arguments.length && this.hasClass('hasDatepicker')) {
if (valCatch.indexOf(placeholder) != -1) {
return valCatch.replace(placeholder, "");
}
}
return valCatch;
}
});
// Insert placeholder as prefix in the value, when user makes a change.
$(".datepicker").datepicker({
onSelect: function(arg) {
$(this).val($(this).attr("placeholder") + arg);
}
});
Here is my Dynamic Add Fields jQuery:
$(document).ready(function() {
//group add limit
var maxGroup = 10;
//add more fields group
$(".addMore").click(function() {
if ($('body').find('.fieldGroup').length < maxGroup) {
var fieldHTML = '<table class="table table-bordered fieldGroup">' + $(".fieldGroupCopy").html() + '</table>';
$('body').find('.fieldGroup:last').after(fieldHTML);
} else {
alert('Maximum ' + maxGroup + ' groups are allowed.');
}
});
//remove fields group
$("body").on("click", ".remove", function() {
$(this).parents(".fieldGroup").remove();
});
});
Updated Image:
jquery html
jquery html
edited Jan 3 at 6:48
Saif Zakir
asked Jan 2 at 14:37
Saif ZakirSaif Zakir
8410
8410
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
This is a popular question on stackoverflow... In short if your inputs comes in the DOM after the page has load you had to use event delegation pattern to initialize all the datepickers. A popular trick is to listen when the document
has focus
.
$( document ).on( "focus", ".datepicker:not(.hasDatepicker)", function() {
var self = this;
$(self).datepicker({
// Your code ....
});
});
working demo
it didn't helped me out.....
– Saif Zakir
Jan 2 at 15:21
i've edit the answer: with:not(.hasDatepicker)
try it
– Emanuele
Jan 2 at 15:31
1
@Saif Zakir this is not a javascript problem but a css image path problem. Look at your css if the image path is correct. If the answer i've wrote has helped you please rate it
– Emanuele
Jan 3 at 8:49
1
If you are using this the file isjquery-ui.css
– Emanuele
Jan 3 at 10:08
1
It's a pleasure. I know you’ll do the same for someone else.
– Emanuele
Jan 3 at 10:19
|
show 4 more comments
When you initialize a plugin:
$(".datepicker").datepicker({
//...
});
This only initializes it on the elements matched at that moment. Matching elements added in the future will need to be initialized after they're added. Note that you'll probably want to more specifically identify the added elements rather than perform a global re-initialization of the plugin on all .datepicker
elements.
The question then becomes, how can you identify specifically your newly added elements? For example, are they specifically in a new containing element to which you already have a reference? If so, you can use that to narrow your selection:
$(".datepicker", someContainingElement).datepicker({
//...
});
Or perhaps the newly added elements are given a specific class which is then removed solely for the purpose of identifying them?:
$(".newdatepicker").datepicker({
//...
}).removeClass("newdatepicker");
There are a variety of options regarding how you would identify your elements, but the main point is that you need to initialize the plugin on any new elements added to the DOM.
Bro my eng is too week i updated my question with dynamic add jQuery function could you help me out.. if you don't mind.
– Saif Zakir
Jan 2 at 15:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008238%2fwhen-i-add-dynamic-field-jquery-datepicket-is-not-wotking%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is a popular question on stackoverflow... In short if your inputs comes in the DOM after the page has load you had to use event delegation pattern to initialize all the datepickers. A popular trick is to listen when the document
has focus
.
$( document ).on( "focus", ".datepicker:not(.hasDatepicker)", function() {
var self = this;
$(self).datepicker({
// Your code ....
});
});
working demo
it didn't helped me out.....
– Saif Zakir
Jan 2 at 15:21
i've edit the answer: with:not(.hasDatepicker)
try it
– Emanuele
Jan 2 at 15:31
1
@Saif Zakir this is not a javascript problem but a css image path problem. Look at your css if the image path is correct. If the answer i've wrote has helped you please rate it
– Emanuele
Jan 3 at 8:49
1
If you are using this the file isjquery-ui.css
– Emanuele
Jan 3 at 10:08
1
It's a pleasure. I know you’ll do the same for someone else.
– Emanuele
Jan 3 at 10:19
|
show 4 more comments
This is a popular question on stackoverflow... In short if your inputs comes in the DOM after the page has load you had to use event delegation pattern to initialize all the datepickers. A popular trick is to listen when the document
has focus
.
$( document ).on( "focus", ".datepicker:not(.hasDatepicker)", function() {
var self = this;
$(self).datepicker({
// Your code ....
});
});
working demo
it didn't helped me out.....
– Saif Zakir
Jan 2 at 15:21
i've edit the answer: with:not(.hasDatepicker)
try it
– Emanuele
Jan 2 at 15:31
1
@Saif Zakir this is not a javascript problem but a css image path problem. Look at your css if the image path is correct. If the answer i've wrote has helped you please rate it
– Emanuele
Jan 3 at 8:49
1
If you are using this the file isjquery-ui.css
– Emanuele
Jan 3 at 10:08
1
It's a pleasure. I know you’ll do the same for someone else.
– Emanuele
Jan 3 at 10:19
|
show 4 more comments
This is a popular question on stackoverflow... In short if your inputs comes in the DOM after the page has load you had to use event delegation pattern to initialize all the datepickers. A popular trick is to listen when the document
has focus
.
$( document ).on( "focus", ".datepicker:not(.hasDatepicker)", function() {
var self = this;
$(self).datepicker({
// Your code ....
});
});
working demo
This is a popular question on stackoverflow... In short if your inputs comes in the DOM after the page has load you had to use event delegation pattern to initialize all the datepickers. A popular trick is to listen when the document
has focus
.
$( document ).on( "focus", ".datepicker:not(.hasDatepicker)", function() {
var self = this;
$(self).datepicker({
// Your code ....
});
});
working demo
edited Jan 2 at 15:43
answered Jan 2 at 15:15
EmanueleEmanuele
665310
665310
it didn't helped me out.....
– Saif Zakir
Jan 2 at 15:21
i've edit the answer: with:not(.hasDatepicker)
try it
– Emanuele
Jan 2 at 15:31
1
@Saif Zakir this is not a javascript problem but a css image path problem. Look at your css if the image path is correct. If the answer i've wrote has helped you please rate it
– Emanuele
Jan 3 at 8:49
1
If you are using this the file isjquery-ui.css
– Emanuele
Jan 3 at 10:08
1
It's a pleasure. I know you’ll do the same for someone else.
– Emanuele
Jan 3 at 10:19
|
show 4 more comments
it didn't helped me out.....
– Saif Zakir
Jan 2 at 15:21
i've edit the answer: with:not(.hasDatepicker)
try it
– Emanuele
Jan 2 at 15:31
1
@Saif Zakir this is not a javascript problem but a css image path problem. Look at your css if the image path is correct. If the answer i've wrote has helped you please rate it
– Emanuele
Jan 3 at 8:49
1
If you are using this the file isjquery-ui.css
– Emanuele
Jan 3 at 10:08
1
It's a pleasure. I know you’ll do the same for someone else.
– Emanuele
Jan 3 at 10:19
it didn't helped me out.....
– Saif Zakir
Jan 2 at 15:21
it didn't helped me out.....
– Saif Zakir
Jan 2 at 15:21
i've edit the answer: with
:not(.hasDatepicker)
try it– Emanuele
Jan 2 at 15:31
i've edit the answer: with
:not(.hasDatepicker)
try it– Emanuele
Jan 2 at 15:31
1
1
@Saif Zakir this is not a javascript problem but a css image path problem. Look at your css if the image path is correct. If the answer i've wrote has helped you please rate it
– Emanuele
Jan 3 at 8:49
@Saif Zakir this is not a javascript problem but a css image path problem. Look at your css if the image path is correct. If the answer i've wrote has helped you please rate it
– Emanuele
Jan 3 at 8:49
1
1
If you are using this the file is
jquery-ui.css
– Emanuele
Jan 3 at 10:08
If you are using this the file is
jquery-ui.css
– Emanuele
Jan 3 at 10:08
1
1
It's a pleasure. I know you’ll do the same for someone else.
– Emanuele
Jan 3 at 10:19
It's a pleasure. I know you’ll do the same for someone else.
– Emanuele
Jan 3 at 10:19
|
show 4 more comments
When you initialize a plugin:
$(".datepicker").datepicker({
//...
});
This only initializes it on the elements matched at that moment. Matching elements added in the future will need to be initialized after they're added. Note that you'll probably want to more specifically identify the added elements rather than perform a global re-initialization of the plugin on all .datepicker
elements.
The question then becomes, how can you identify specifically your newly added elements? For example, are they specifically in a new containing element to which you already have a reference? If so, you can use that to narrow your selection:
$(".datepicker", someContainingElement).datepicker({
//...
});
Or perhaps the newly added elements are given a specific class which is then removed solely for the purpose of identifying them?:
$(".newdatepicker").datepicker({
//...
}).removeClass("newdatepicker");
There are a variety of options regarding how you would identify your elements, but the main point is that you need to initialize the plugin on any new elements added to the DOM.
Bro my eng is too week i updated my question with dynamic add jQuery function could you help me out.. if you don't mind.
– Saif Zakir
Jan 2 at 15:19
add a comment |
When you initialize a plugin:
$(".datepicker").datepicker({
//...
});
This only initializes it on the elements matched at that moment. Matching elements added in the future will need to be initialized after they're added. Note that you'll probably want to more specifically identify the added elements rather than perform a global re-initialization of the plugin on all .datepicker
elements.
The question then becomes, how can you identify specifically your newly added elements? For example, are they specifically in a new containing element to which you already have a reference? If so, you can use that to narrow your selection:
$(".datepicker", someContainingElement).datepicker({
//...
});
Or perhaps the newly added elements are given a specific class which is then removed solely for the purpose of identifying them?:
$(".newdatepicker").datepicker({
//...
}).removeClass("newdatepicker");
There are a variety of options regarding how you would identify your elements, but the main point is that you need to initialize the plugin on any new elements added to the DOM.
Bro my eng is too week i updated my question with dynamic add jQuery function could you help me out.. if you don't mind.
– Saif Zakir
Jan 2 at 15:19
add a comment |
When you initialize a plugin:
$(".datepicker").datepicker({
//...
});
This only initializes it on the elements matched at that moment. Matching elements added in the future will need to be initialized after they're added. Note that you'll probably want to more specifically identify the added elements rather than perform a global re-initialization of the plugin on all .datepicker
elements.
The question then becomes, how can you identify specifically your newly added elements? For example, are they specifically in a new containing element to which you already have a reference? If so, you can use that to narrow your selection:
$(".datepicker", someContainingElement).datepicker({
//...
});
Or perhaps the newly added elements are given a specific class which is then removed solely for the purpose of identifying them?:
$(".newdatepicker").datepicker({
//...
}).removeClass("newdatepicker");
There are a variety of options regarding how you would identify your elements, but the main point is that you need to initialize the plugin on any new elements added to the DOM.
When you initialize a plugin:
$(".datepicker").datepicker({
//...
});
This only initializes it on the elements matched at that moment. Matching elements added in the future will need to be initialized after they're added. Note that you'll probably want to more specifically identify the added elements rather than perform a global re-initialization of the plugin on all .datepicker
elements.
The question then becomes, how can you identify specifically your newly added elements? For example, are they specifically in a new containing element to which you already have a reference? If so, you can use that to narrow your selection:
$(".datepicker", someContainingElement).datepicker({
//...
});
Or perhaps the newly added elements are given a specific class which is then removed solely for the purpose of identifying them?:
$(".newdatepicker").datepicker({
//...
}).removeClass("newdatepicker");
There are a variety of options regarding how you would identify your elements, but the main point is that you need to initialize the plugin on any new elements added to the DOM.
answered Jan 2 at 15:04
DavidDavid
150k28146212
150k28146212
Bro my eng is too week i updated my question with dynamic add jQuery function could you help me out.. if you don't mind.
– Saif Zakir
Jan 2 at 15:19
add a comment |
Bro my eng is too week i updated my question with dynamic add jQuery function could you help me out.. if you don't mind.
– Saif Zakir
Jan 2 at 15:19
Bro my eng is too week i updated my question with dynamic add jQuery function could you help me out.. if you don't mind.
– Saif Zakir
Jan 2 at 15:19
Bro my eng is too week i updated my question with dynamic add jQuery function could you help me out.. if you don't mind.
– Saif Zakir
Jan 2 at 15:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008238%2fwhen-i-add-dynamic-field-jquery-datepicket-is-not-wotking%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown