Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
DatePicker: Select single date when using range selection

I have a range DatePicker from Primefaces. But I also want to be able to just select one date.

But if i do so, i won't get any values, just a empty array. This is because the internal function (which i can't modify) only returns something when two values are given. Or at least I think that.

The workaround which i thought of was just taking the first value of the array by calling it with a javascript function, but i can't access it, because the PF function has neither a function name nor a class.

Here the code of the PrimeFaces function:

 if (this.isRangeSelection()) {
                                if (this.value && this.value.length) {
                                    var b = this.value[0],
                                        g = this.value[1];
                                    d = this.formatDateTime(b);
                                    if (g) {
                                        d += " " + this.options.rangeSeparator + " " + this.formatDateTime(g)
                                    }
                                }
                            }

Here is my poor javascript attempt:

<script type="text/javascript">
    function getArrayValue(){
        console.log("inFunction");
        console.log(window.d.value[0]);
    }
    </script>

This is called with this:

<div class="p-field p-col-12 p-md-4">
    <p:datePicker id="range" selectionMode="range"
            value="#{SearchBean.range}" onblur="getArrayValue()">
    </p:datePicker>
 </div>

Thanks for your help in advance! :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I just helped a friend do the same thing that sets the range to both dates being the same you can do it with this JS...

<script type="text/javascript">
function adjustDateRange(widgetVar) {
    var widget = PF(widgetVar);
    var dates = widget.getDate();
    if (dates[0] && !dates[1]) {
        dates[1] = dates[0];
        widget.jq.data().primeDatePicker.updateModel(null, dates);
    }
}
</script>

Then in your DatePicker...

<p:datePicker id="range" 
widgetVar="wgtRange" 
selectionMode="range" 
value="#{SearchBean.range}" 
onblur="adjustDateRange('wgtRange')">
</p:datePicker>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda