I'm trying to use the datepicker function but I'm getting a error.
There is a lot of topic about this problem but every time i try a different method, it doesn't work (with .noconflict() -> maybe i'm using it wrong).
I would like to change the start date and the end date to the current date when I change the button.
I'm starting JS, can you help me ? May be an other function ? pls
package.json :
{
"devDependencies": {
...
"jquery": "^3.5.1",
...
}
"dependencies": {
...
"jquery-ui": "^1.12.1",
...
}
}
JS code :
const $ = require('jquery');
$( document ).ready( function() {
$('.form-check').on('change', function () {
if( $("[type='radio']:checked").val() == '1')
{
$('.form-period').show();
$('.form-date').hide();
} else {
$('.form-period').hide();
$('.form-date').show();
}
$('.js-datepicker').datepicker("setDate", new Date());
$('.alert').remove();
});
});
Console :
Uncaught TypeError: $(...).datepicker is not a function
Edit : HTML is generated by the symfony code :
->add('searchStartAt', DateType::class, [
'label' => 'Date de début',
'widget' => 'single_text',
'required' => false,
'data' => new \DateTime('now'),
'attr' => ['class' => 'js-datepicker']
])
->add('searchEndAt', DateType::class, [
'label' => 'Date de fin',
'widget' => 'single_text',
'required' => false,
'data' => new \DateTime('now'),
'attr' => ['class' => 'js-datepicker']
])
End of my file html.twig :
{% block javascripts %}
{{ parent() }}
{{ encore_entry_script_tags('choice_form_stats') }}
{% endblock %}
webpack.config.js :
var Encore = require('@symfony/webpack-encore');
Encore
.addEntry('choice_form_stats', './assets/choice_form_stats.js')
...
;
module.exports = Encore.getWebpackConfig();
app.js :
const $ = require('jquery');
require('bootstrap');
require('jquery-ui');
thanks,
setDate
method. Simply add$('.js-datepicker').datepicker();
to the beginning of your Ready statement.<HEAD>
and<SCRIPT>
sections. It sounds like you are not loading the jQuery UI library.