简体   繁体   中英

How to pre-populate a datetime-local value in an EJS form

I am currently trying to have a form pre-populate with information from my database for users to view and edit. The EJS form is populating all information except for a datetime-local variable, and I am stumped. Here is the code for the EJS form:

<div class="well">
    <form action="/deleteProposal" method="post">
        <div class="form-group">
            <label>Event Name</label>
            <input type="text" class="form-control" name="eventName" value="<%= Proposal[0].eventName%>">
        </div>
        <div class="form-group">
            <label>Event Date and Time</label>
            <input type="datetime-local" class="form-control" name="eventDateTime" value="<%=Proposal[0].eventDateTime%>">
        </div>
        <div class="form-group">
            <label>Event Location</label>
            <input type="text" class="form-control" name="eventLocation" value="<%= Proposal[0].eventLocation%>">
        </div>
        <div class="form-group">
            <label>Event Description</label>
            <input type="text" class="form-control" name="eventDescription" value="<%= Proposal[0].eventDescription%>">
        </div>
        <div class="form-group">
            <label>Learning Outcome</label>
            <input type="text" class="form-control" name="learningOutcome" value="<%= Proposal[0].learningOutcome%>">
        </div>
        <div class="form-group">
            <label>Event PRA</label>
            <input type="text" class="form-control" name="eventPRA" value="<%= Proposal[0].eventPRA%>">
        </div>
</div>

Any help or tips would be appreciated, as I am pretty new at Node.JS. Thanks! :)

The <input type="datetime-local"> field can prepopulated with the format YYYY-MM-DDTHH:MM . Must be 0-padded numerics.

Nor does it take a timezone identifier. It assumes local client time. Therefor, it is advisable to pass along a TZ offset (or equivalent) along in the form for proper date maths later.

<input type="hidden" id="tz" name="tz">
<script>
document.getElementById("tz").value = new Date().getTimezoneOffset();
</script>

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