Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date object in meteor and autoform

I have problem with input Date validation on Meteor, AutoForm and Simple-schema .

If its turn on Chrome auto date picker , validation can't recognize Date format or type like is in schema (type: Date) or from input (type="date") "08/19/2014"

If its turn off Chrome date picker, and when i use bootstrap3-datepicker and with moment js set format to "2014-08-19" like they wrote, I have same Date validation problem.

  1. What kind date format can be correct validated in schema with type: Date ?
  2. Which date picker is best to give me correct date format and type and can you please give me an example because in meteor-autoform-example i saw same problem.

Example:

.js

schema: {
    'orderDate': {
        type: Date,
        label: "OrderDate",
        optional: true
        }

.html

{{>afQuickField name="orderDate" type="date" }}

or with {{#autoForm}}

<div class="form-group {{#if afFieldIsInvalid name='orderDate'}}has-error{{/if}}">
  {{> afFieldLabel name='orderDate'}}
  <span class="help-block">*Requered</span>
  {{> afFieldInput name='orderDate' id="OrderDate"}}
  {{#if afFieldIsInvalid name='orderDate'}}
<span class="help-block">{{{afFieldMessage name='orderDate'}}}</span>
{{/if}}
</div>

or with bootstrap3-datepicker

<input type="date" id="orderPickerDate" class="form-control" />

Thank you.

like image 848
satmari Avatar asked Aug 19 '14 18:08

satmari


1 Answers

The date format is a combination of d, dd, D, DD, m, mm, M, MM, yy, yyyy.

d, dd: Numeric date, no leading zero and leading zero, respectively. Eg, 5, 05.
D, DD: Abbreviated and full weekday names, respectively. Eg, Mon, Monday.
m, mm: Numeric month, no leading zero and leading zero, respectively. Eg, 7, 07.
M, MM: Abbreviated and full month names, respectively. Eg, Jan, January
yy, yyyy: 2- and 4-digit years, respectively. Eg, 12, 2012.

You can specify this format on data-date-format, but a better place to add format is in the schema:

some_date: {
    type: Date,
    autoform: {
      type: "bootstrap-datepicker",
      datePickerOptions: {
        autoclose: true,
        format: 'dd M yyyy'
      }
    }
  },

For example, dd M yyyy give you 27 Apr 2017.

I found the documentation at http://bootstrap-datepicker.readthedocs.io/en/latest/options.html

like image 115
Saeed D. Avatar answered Oct 14 '22 10:10

Saeed D.