How to schedule an event on datepicker?

Asked

Viewed 568 times

4

I have this code in javascript:

 $(function() {
      $("#calendario").datepicker({
        changeMonth: true,
        todayHighlight: true,
        changeYear: true,
        showOtherMonths: true,
        selectOtherMonths: true,
        dateFormat: 'dd/mm/yy',
        dayNames: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado', 'Domingo'],
        dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S', 'D'],
        dayNamesShort: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb', 'Dom'],
        monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
        ;
        monthNamesShort: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro']
      });
    });


<div id="calendario"> </div>

And only the div above to call the calendar.

How do I register a value on datepicker? Remembering that it has to be manageable, IE, can register more than 1.

  • Lucas which datapicker is this ? of bootstrap or jqueryui?

  • @Highlander, would be the jqueryui, but I have several dates to register in the month, IE, several events.

1 answer

1

Come on, first thing, remove the semicolon causing syntax error [Line 12].

Now let’s have your doubts:

How do I register a datepicker value?

When you talk about registration gets a little broad, it can be two things in my view.

1 - Set a Default value:

$("#calendario").datepicker( "setDate", "10/12/2015" );

2 - Pick a selected value:

onSelect: function() {
  var dateAsObject = $(this).datepicker('getDate'); // pega valor selecionado
  console.log(dateAsObject);
}

Example working on: Jsfiddle

But if you want to be selected in the same field several example dates 25/12/2015,26/12/2015 etc... You will have to use a Plugin because this is not supported in jQueryUI datepicker ;(

A plugin you can use is: Multdatepicker

  • Actually that’s right, I need several dates.

  • A friend said it’s possible, but complicated. But I tried several ways and could not, today’s date for example, it applies a formatting.

  • @Lucashenriquedutra Then follow the solution of the plugin Multdatepicker, if your friend said it is possible it would be interesting to ask him to answer your question why could help people in the future, I experience say that there is no way to do, but there are always exceptions;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.