Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I am using the datetime editable region.
But in the front end I want the date and time to be displayed as a HTML input type date and input type time.

When I use
Code: Select all
<cms:hide>
    <cms:input type="bound" name="input_type_date_time" />
</cms:hide>
<input type="datetime-local" name="f_input_type_date_time"  />

It works correctly.

But when I use:
Code: Select all
<cms:hide>
    <cms:input type="bound" name="input_type_date_time" />
</cms:hide>
<input type="date" name="f_input_type_date_time">
<cms:hide>
    <cms:input type="bound" name="input_type_date_time" />
</cms:hide>
<input type="time" name="f_input_type_date_time">

It saves the date as:
1970-01-01 00:00
what ever be the date that i fill in. (this only happens when field is not set to required | if set to required it says invalid date).

What can i do? or should i consider a different approach? Please advise.

For what I am trying to use the code is below:
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Date and Time Fields' clonable='1' >
   <cms:editable name='input_type_date' label='Input Type = Date' type='datetime' format='Y-m-d' order='1' />
   <cms:editable name='input_type_time' label='Input Type = Time' type='datetime' format='H:i' only_time='1' allow_time='1' am_pm='0' order='2' />
   <cms:editable name='input_type_date_time' label='Input Type = Date and Time' type='datetime' format='Y-m-d H:i' allow_time='1' am_pm='0' order='3' />
</cms:template>
<!DOCTYPE html>
<html>
   <head>
      <title>Date and Time Input: CouchCMS</title>
      <link rel="stylesheet" type="text/css" href="<cms:show k_site_link />assets/css/gxcpl.css">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
   </head>
   <body>
       <cms:form
           masterpage=k_template_name
           mode='create'
           enctype='multipart/form-data'
           method='post'
           anchor='0'
       >

           <cms:if k_success >
               <cms:db_persist_form
                   _invalidate_cache='0'
                   _auto_title='1'
               />
               <cms:if k_success>
                  <cms:set_flash name='submit_success' value='1' />
                  <cms:redirect k_page_link />
              </cms:if>
           </cms:if>

           <table class="gxcpl-table">
              <thead>
                 <tr>
                    <th width="33%">
                       Component
                    </th>
                    <th width="33%">
                       HTML
                    </th>
                    <th width="34%">
                       COUCH
                    </th>
                 </tr>
              </thead>
              <tbody>
                 <tr>
                    <td>
                       Input <em>type="date"</em>
                    </td>
                    <td>
                       <input type="date" name="" />
                    </td>
                    <td>
                       <cms:hide>
                          <cms:input type="bound" name="input_type_date" />
                       </cms:hide>
                       <input type="date" name="f_input_type_date" />
                    </td>
                 </tr>
                 <tr>
                    <td>
                       Input <em>type="time"</em>
                    </td>
                    <td>
                       <input type="time" name="" />
                    </td>
                    <td>
                       <cms:hide>
                          <cms:input type="bound" name="input_type_time" />
                       </cms:hide>
                       <input type="time" name="f_input_type_time" />
                    </td>
                 </tr>
                 <tr>
                    <td>
                       Input <em>type="datetime"</em>
                    </td>
                    <td>
                       <input type="datetime-local" name="" />
                    </td>
                    <td>
                       <cms:ignore>
                       <cms:hide>
                          <cms:input type="bound" name="input_type_date_time" />
                       </cms:hide>
                       <input type="datetime-local" name="f_input_type_date_time"  />
                       </cms:ignore>

                       
                       <cms:hide>
                          <cms:input type="bound" name="input_type_date_time" />
                       </cms:hide>
                       <input type="date" name="f_input_type_date_time">
                       <cms:hide>
                          <cms:input type="bound" name="input_type_date_time" />
                       </cms:hide>
                       <input type="time" name="f_input_type_date_time">
                       
                    </td>
                 </tr>
              </tbody>
              <tfooter>
                 <tr>
                    <td colspan="3">
                       <div class="container">
                          <div class="row">
                             <div class="col-md-2">
                                <strong>Alert Message</strong>
                             </div>
                             <div class="col-md-10">
                                <cms:set submit_success="<cms:get_flash 'submit_success' />" />
                              <cms:if submit_success >
                                  <div class="alert alert-success">
                                      <strong>Success:</strong> Your application has been submitted.
                                  </div>
                              </cms:if>
                     
                                <cms:if k_error >
                                    <div class="error">
                                       <cms:each k_error >
                                          <div class="alert alert-danger">
                                               <cms:show item /><br>
                                            </div>
                                       </cms:each>
                                    </div>
                                </cms:if>
                            </div>
                        </div>
                     </div>
                    </td>
                 </tr>
              </tfooter>
           </table>

           <div class="gxcpl-ptop-20"></div>

           <div class="container">
              <div class="row">
                 <div class="col-md-12">
                    <center>
                       <button class="btn btn-danger btn-sm" type="submit">
                          SAVE
                       </button>
                    </center>
                 </div>
              </div>
           </div>

       </cms:form>

       <div class="gxcpl-ptop-50"></div>

       <table class="gxcpl-table" id="ho">
          <thead>
             <tr>
                <th class="text-center" width="10%">
                   #
                </th>
                <th width="30%">
                   Input <em>type=date</em>
                </th>
                <th width="30%">
                   Input <em>type=time</em>
                </th>
                <th width="30%">
                   Input <em>type=datetime</em>
                </th>
             </tr>
          </thead>
          <tbody>
             <cms:pages masterapge=k_template_name show_future_entries='1'>
             <cms:no_results>
                <tr>
                   <td colspan="4" class="text-center">
                      - No result -
                   </td>
                </tr>
             </cms:no_results>
             <tr>
                <td class="text-center">
                   
                </td>
                <td>
                   <cms:date input_type_date format='Y-m-d' />
                </td>
                <td>
                   <cms:date input_type_time format='H:i' />      
                </td>
                <td>
                   <cms:date input_type_date_time format='Y-m-d H:i' />
                </td>
             </tr>
             </cms:pages>
          </tbody>
       </table>

       <!-- Scripts -->
       <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
       <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
       <!-- Scripts -->
   </body>
</html>
<?php COUCH::invoke(); ?>
Image
where innovation meets technology
instead of using date and time as two separate regions, I wonder why you are not willing to use only a single combined datetime region?

On the front end you can easily parse out and display the date and time separately.
@KK Sir.
Actually it is not about displaying the date. That I know can be done.

instead of using date and time as two separate regions, I wonder why you are not willing to use only a single combined datetime region?


On the front end i am trying to use the date and time input regions.
I had earlier created two separate editables for date and time but then when i need to use the date and time to set something on the front end they appear in two separate regions.

SO i thought if i could use a single region but show two different input in the DBF it would be fine when i need to use the date and time together.

I am actually wanting to save the arrival date and arrival time of a train.
Now when a train is handed over from one division to another division of the Indian Railways, the division receiving it creates an entry for arrival date of that train (as a forecast). But the time is entered only when the train actually reaches the station.

A similar field is the Sign On field in the same form. This actually marks the date and time a loco pilot boarded the train. Again the same thing happens here. Date is entered first when the loco pilot reports on duty. Time is entered when he boards the train. And if the loco pilot is driving the train for more than 8hrs then the signon time field (in a reeport table) needs to be marked with a red background, stating that the loco pilot is overdue and needs to un-board the train for rest.

The client wants the date field to be in DD/MM/YYYY format to enter the date (doable using the input type='date') and time in 24hrs format but something like XX:XX (no am or pm and using the input type='time'). I am unable to save the time through the DBF independently.

I am using a single date time editable region in the backend. But in the front end i need to show them separate fields. Also, the display format has to be as mentioned above and not the couch standard display format.

Please advise sir.

Regards,
GenXCoders (Aashish)
Image
where innovation meets technology
3 posts Page 1 of 1
cron