js-datepicker mutiple inputs with the same classHow to change an element's class with JavaScript?How can I select an element with multiple classes in jQuery?Disable/enable an input with jQuery?Disable same origin policy in ChromeJQueryUI DatePicker replacing invalid input with minDateExtending jQuery UI components ( Overriding jQuery Datepicker to prevent wrong input)UI-Bootstrap datepicker with input maskAngular 2 with javascript and datepickerDon't display datepicker popup in mobile devices for input type=dateJquery UI datepicker add “Unknown” option value to input

How can we prove that any integral in the set of non-elementary integrals cannot be expressed in the form of elementary functions?

Method to test if a number is a perfect power?

Class Action - which options I have?

Pre-amplifier input protection

Do the temporary hit points from the Battlerager barbarian's Reckless Abandon stack if I make multiple attacks on my turn?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

What is the opposite of 'gravitas'?

How did Doctor Strange see the winning outcome in Avengers: Infinity War?

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?

Is expanding the research of a group into machine learning as a PhD student risky?

How does it work when somebody invests in my business?

Would a virus be able to change eye and hair colour?

What can we do to stop prior company from asking us questions?

How do I find the solutions of the following equation?

Short story about space worker geeks who zone out by 'listening' to radiation from stars

System.debug(JSON.Serialize(o)) Not longer shows full string

Increase performance creating Mandelbrot set in python

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

How easy is it to start Magic from scratch?

Purchasing a ticket for someone else in another country?

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

How did Arya survive the stabbing?

How does the UK government determine the size of a mandate?



js-datepicker mutiple inputs with the same class


How to change an element's class with JavaScript?How can I select an element with multiple classes in jQuery?Disable/enable an input with jQuery?Disable same origin policy in ChromeJQueryUI DatePicker replacing invalid input with minDateExtending jQuery UI components ( Overriding jQuery Datepicker to prevent wrong input)UI-Bootstrap datepicker with input maskAngular 2 with javascript and datepickerDon't display datepicker popup in mobile devices for input type=dateJquery UI datepicker add “Unknown” option value to input













0















I'm using this js-datepicker plugin (https://www.npmjs.com/package/js-datepicker). The problem is I have a lot of fields I want to apply the same type of date picker so presumed I could just give them all a class of say 'year', however it only assigns it to the first input field with that class. Is there a way to apply to all inputs with that class?



my code:



const year = datepicker('.year', 
/* formatter: (input, date, instance) =>
const value = date.toLocaleDateString()
input.value = value // => '1/1/2099'
*/
);









share|improve this question

















  • 1





    Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.

    – 04FS
    Mar 8 at 11:29











  • They would all be assigned to same const variable, that's why it is appended only to the first element. You'd have to create an array of const and possibly differentiate the DOM elements by something more specific like an id value

    – Davide Vitali
    Mar 8 at 11:29















0















I'm using this js-datepicker plugin (https://www.npmjs.com/package/js-datepicker). The problem is I have a lot of fields I want to apply the same type of date picker so presumed I could just give them all a class of say 'year', however it only assigns it to the first input field with that class. Is there a way to apply to all inputs with that class?



my code:



const year = datepicker('.year', 
/* formatter: (input, date, instance) =>
const value = date.toLocaleDateString()
input.value = value // => '1/1/2099'
*/
);









share|improve this question

















  • 1





    Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.

    – 04FS
    Mar 8 at 11:29











  • They would all be assigned to same const variable, that's why it is appended only to the first element. You'd have to create an array of const and possibly differentiate the DOM elements by something more specific like an id value

    – Davide Vitali
    Mar 8 at 11:29













0












0








0








I'm using this js-datepicker plugin (https://www.npmjs.com/package/js-datepicker). The problem is I have a lot of fields I want to apply the same type of date picker so presumed I could just give them all a class of say 'year', however it only assigns it to the first input field with that class. Is there a way to apply to all inputs with that class?



my code:



const year = datepicker('.year', 
/* formatter: (input, date, instance) =>
const value = date.toLocaleDateString()
input.value = value // => '1/1/2099'
*/
);









share|improve this question














I'm using this js-datepicker plugin (https://www.npmjs.com/package/js-datepicker). The problem is I have a lot of fields I want to apply the same type of date picker so presumed I could just give them all a class of say 'year', however it only assigns it to the first input field with that class. Is there a way to apply to all inputs with that class?



my code:



const year = datepicker('.year', 
/* formatter: (input, date, instance) =>
const value = date.toLocaleDateString()
input.value = value // => '1/1/2099'
*/
);






javascript npm jsdatepick






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 11:22









karlkarl

467




467







  • 1





    Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.

    – 04FS
    Mar 8 at 11:29











  • They would all be assigned to same const variable, that's why it is appended only to the first element. You'd have to create an array of const and possibly differentiate the DOM elements by something more specific like an id value

    – Davide Vitali
    Mar 8 at 11:29












  • 1





    Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.

    – 04FS
    Mar 8 at 11:29











  • They would all be assigned to same const variable, that's why it is appended only to the first element. You'd have to create an array of const and possibly differentiate the DOM elements by something more specific like an id value

    – Davide Vitali
    Mar 8 at 11:29







1




1





Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.

– 04FS
Mar 8 at 11:29





Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.

– 04FS
Mar 8 at 11:29













They would all be assigned to same const variable, that's why it is appended only to the first element. You'd have to create an array of const and possibly differentiate the DOM elements by something more specific like an id value

– Davide Vitali
Mar 8 at 11:29





They would all be assigned to same const variable, that's why it is appended only to the first element. You'd have to create an array of const and possibly differentiate the DOM elements by something more specific like an id value

– Davide Vitali
Mar 8 at 11:29












2 Answers
2






active

oldest

votes


















0














Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.



Basically something simple like this should do,



var fields = document.querySelectorAll('.year');

fields.forEach(function(e)
datepicker(e, )
);


If you need the references to the datepicker instances to be able to modify options later on or something like that, you could add them to an array inside the loop.






share|improve this answer























  • awesome, looks like the best solution cheers!

    – karl
    Mar 8 at 12:12


















0














Maybe you can simply use input type "date" to have a quick working solution.
Advantage: Format is chosen based on the current settings of the user, no need to format anything.






<input type="date" value="2019-01-01">








share|improve this answer























  • Hi Aaron, yes this is how I first wanted to do it but unfortunately there's no way of customising the output, it has to go into a specific date format which is likely different to the browser preference.

    – karl
    Mar 8 at 12:14










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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062216%2fjs-datepicker-mutiple-inputs-with-the-same-class%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









0














Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.



Basically something simple like this should do,



var fields = document.querySelectorAll('.year');

fields.forEach(function(e)
datepicker(e, )
);


If you need the references to the datepicker instances to be able to modify options later on or something like that, you could add them to an array inside the loop.






share|improve this answer























  • awesome, looks like the best solution cheers!

    – karl
    Mar 8 at 12:12















0














Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.



Basically something simple like this should do,



var fields = document.querySelectorAll('.year');

fields.forEach(function(e)
datepicker(e, )
);


If you need the references to the datepicker instances to be able to modify options later on or something like that, you could add them to an array inside the loop.






share|improve this answer























  • awesome, looks like the best solution cheers!

    – karl
    Mar 8 at 12:12













0












0








0







Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.



Basically something simple like this should do,



var fields = document.querySelectorAll('.year');

fields.forEach(function(e)
datepicker(e, )
);


If you need the references to the datepicker instances to be able to modify options later on or something like that, you could add them to an array inside the loop.






share|improve this answer













Looks like this wants to initialize for one element at a time only, so you will need to select all your .year elements and loop over them, and then call the datepicker function for each one individually.



Basically something simple like this should do,



var fields = document.querySelectorAll('.year');

fields.forEach(function(e)
datepicker(e, )
);


If you need the references to the datepicker instances to be able to modify options later on or something like that, you could add them to an array inside the loop.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 11:32









04FS04FS

1,3241314




1,3241314












  • awesome, looks like the best solution cheers!

    – karl
    Mar 8 at 12:12

















  • awesome, looks like the best solution cheers!

    – karl
    Mar 8 at 12:12
















awesome, looks like the best solution cheers!

– karl
Mar 8 at 12:12





awesome, looks like the best solution cheers!

– karl
Mar 8 at 12:12













0














Maybe you can simply use input type "date" to have a quick working solution.
Advantage: Format is chosen based on the current settings of the user, no need to format anything.






<input type="date" value="2019-01-01">








share|improve this answer























  • Hi Aaron, yes this is how I first wanted to do it but unfortunately there's no way of customising the output, it has to go into a specific date format which is likely different to the browser preference.

    – karl
    Mar 8 at 12:14















0














Maybe you can simply use input type "date" to have a quick working solution.
Advantage: Format is chosen based on the current settings of the user, no need to format anything.






<input type="date" value="2019-01-01">








share|improve this answer























  • Hi Aaron, yes this is how I first wanted to do it but unfortunately there's no way of customising the output, it has to go into a specific date format which is likely different to the browser preference.

    – karl
    Mar 8 at 12:14













0












0








0







Maybe you can simply use input type "date" to have a quick working solution.
Advantage: Format is chosen based on the current settings of the user, no need to format anything.






<input type="date" value="2019-01-01">








share|improve this answer













Maybe you can simply use input type "date" to have a quick working solution.
Advantage: Format is chosen based on the current settings of the user, no need to format anything.






<input type="date" value="2019-01-01">








<input type="date" value="2019-01-01">





<input type="date" value="2019-01-01">






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 11:30









AaronAaron

13




13












  • Hi Aaron, yes this is how I first wanted to do it but unfortunately there's no way of customising the output, it has to go into a specific date format which is likely different to the browser preference.

    – karl
    Mar 8 at 12:14

















  • Hi Aaron, yes this is how I first wanted to do it but unfortunately there's no way of customising the output, it has to go into a specific date format which is likely different to the browser preference.

    – karl
    Mar 8 at 12:14
















Hi Aaron, yes this is how I first wanted to do it but unfortunately there's no way of customising the output, it has to go into a specific date format which is likely different to the browser preference.

– karl
Mar 8 at 12:14





Hi Aaron, yes this is how I first wanted to do it but unfortunately there's no way of customising the output, it has to go into a specific date format which is likely different to the browser preference.

– karl
Mar 8 at 12:14

















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062216%2fjs-datepicker-mutiple-inputs-with-the-same-class%23new-answer', 'question_page');

);

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







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme