简体   繁体   中英

Check if calendar field is empty

Ok so i have a calendar field:

<p:calendar id="dateOfBirth" mode="popup" placeholder="Date Of Birth" navigator="true" yearRange="c-18:c" pattern="dd.MM.yyyy"/>

And in javascript i want to check if the field has been entered a date:

if($("#dateOfBirth").val() === ""){
    errors.push("dateOfBirth");
}

But it is not working. How can i make this equality in order to check that the user has skipped the field without entering anything?

p:calendar renders not just as a HTML input element. But it contains an input element which has the id you specified plus a postfix, which is _input . So your code should work if you change it to the following

if($("#dateOfBirth_input").val() === ""){
   errors.push("dateOfBirth");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM