landa
landa

Reputation: 263

How to clear calendar input with java script

JavaScript function after clicking on clear button

function resetTime() {
    document.getElementById("to_time").valueAsDate = null;
}

PrimeFaces calendar tag

<p:calendar id="to_time"
            value="#{anomaliesList.toDate}"
            readonlyInput="true"
            maxdate="#{currentDate}"
            size="16"
            pattern="dd/MM/yyyy HH:mm" />

Upvotes: 1

Views: 646

Answers (1)

Jasper de Vries
Jasper de Vries

Reputation: 20188

First of all, p:calendar is deprecated. Use p:datePicker instead.

The easiest way to deal with this is setting a widgetVar on your p:datePicker. This allows you to use the client side API.

To reset a date, use:

PF('yourWidgetName').setDate(null);

Note that if you want to use getElementById you probably need to incorporate the form clientId.

See also:

Upvotes: 1

Related Questions