Giter VIP home page Giter VIP logo

angular-schema-form-datepicker's Introduction

Angular Schema Form Date Picker Add-on

This is an add-on for Angular Schema Form.

Build Status Bower version

Everyone loves a nice date picker - now you can have your very own date picker in Schema Form! The date picker add-on uses the excellent jQuery-based date picker, pickadate.js.

Dates in JSON Schema are of type "string" and follow the RFC 3339 date fomat, which, in turn, follows ISO 8601. What does that mean for you? Basically, just stick with the format yyyy-mm-dd and you'll be fine (...but you can change it if you must).

Within Schema Form, pickadate only supports dates - not times.

Installation

The date picker is an add-on to the Bootstrap decorator. To use it, just include bootstrap-datepicker.min.js after bootstrap-decorator.min.js.

You'll need to load a few additional files to use pickadate in this order:

  1. jQuery (pickadate depends on it)
  2. The pickadate source files (see the pickadate.js GitHub page for documentation)
  3. The pickadate CSS (you'll have to choose theme)
  4. Translation files for whatever language you want to use

Easiest way is to install is with bower, this will also include dependencies:

$ bower install angular-schema-form-datepicker

Usage

The datepicker add-on adds a new form type, datepicker, and a new default mapping.

Form Type Becomes
datepicker a pickadate widget
Schema Default Form type
"type": "string" and "format": "date" datepicker

Form Type Options

The datepicker form type takes two date range options: minDate and maxDate. minDate and maxDate both accept one of the following as values:

  1. A string in the format yyyy-mm-dd,
  2. A unix timestamp (as a Number), or
  3. An instance of Date

It is also possible to set the date format using the format option, which is used to format the date stored by AngularJS, but note that in doing so you break the standard and other JSON Schema validators might complain. The view date displayed by pickadate is set by the translation files. see Installation

Example

Below is an example. It's written in javascript instead of pure schema and form so the use of the date object is supported.

scope.schema = {
  "type": "object",
  "properties": {
    "birthDate": {
      "title": "Bday",
      "type": "string",
      "format": "date"
    }
  }
}

scope.form = [
  {
    "key": "birthDate",
    "minDate": "1995-09-01",
    "maxDate": new Date(),
    "format": "yyyy-mm-dd"
  }
]

angular-schema-form-datepicker's People

Contributors

davidlgj avatar dervisevic avatar etodanik avatar iainbeeston avatar jamesguthrie avatar kornosaurus avatar ulion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-schema-form-datepicker's Issues

no feedback icons

I tried to add it back, but I have no idea when to trigger form validation on date change.

Here is the template code I edited, added feedback span and decorator class bindings. But it always shows glyphicon-ok.

angular.module("schemaForm").run(["$templateCache", function($templateCache) {$templateCache.put("directives/decorators/bootstrap/datepicker/datepicker.html","<div class=\"form-group {{form.htmlClass}}\" ng-class=\"{'has-error': form.disableErrorState !== true && hasError(), 'has-success': form.disableSuccessState !== true && hasSuccess(), 'has-feedback': form.feedback !== false }\">\n  <label class=\"control-label\" ng-show=\"showTitle()\">{{form.title}}</label>\n  <div ng-class=\"{\'input-group\': (form.fieldAddonLeft || form.fieldAddonRight)}\">\n    <span ng-if=\"form.fieldAddonLeft\"\n          class=\"input-group-addon\"\n          ng-bind-html=\"form.fieldAddonLeft\"></span>\n    <input ng-show=\"form.key\"\n           style=\"background-color: white\"\n           type=\"text\"\n           class=\"form-control {{form.fieldHtmlClass}}\"\n           schema-validate=\"form\"\n           ng-model=\"$$value$$\"\n           ng-disabled=\"form.readonly\"\n           pick-a-date=\"form.pickadate\"\n           min-date=\"form.minDate\"\n           max-date=\"form.maxDate\"\n           name=\"{{form.key.slice(-1)[0]}}\"\n           format=\"form.format\" />\n    <span ng-if=\"form.fieldAddonRight\"\n          class=\"input-group-addon\"\n          ng-bind-html=\"form.fieldAddonRight\"></span>\n  </div>\n  <span ng-if=\"form.feedback !== false\" class=\"form-control-feedback\" ng-class=\"evalInScope(form.feedback) || { 'glyphicon': true, 'glyphicon-ok': hasSuccess(), 'glyphicon-remove': hasError() }\"></span>\n  <span class=\"help-block\">{{ (hasError() && errorMessage(schemaError())) || form.description}}</span>\n</div>\n");}]);

How should I change the code in pickADate directive?

Setting the container attribute, doesn't affect the root

Hello,

we are using this datepicker and we have problems when it is placed inside of the modal dialog view. We tried to set explicitely the root element to #content but it seems not to work. The attribute i am talking about is: http://amsul.ca/pickadate.js/date/#container

 <input style="background-color: white"
             type="text"
             class="form-control"
             ng-model="dialog.fromDate"
             pick-a-date="date"
             container="#content"
             format="YYYY-MM-DD"/>

Does it work?

not working in angular drywall

date picker is not working in angular drywall..need quick solution..

schema:
"date1": {
"title": " ",
"type": "string",
"format": "date"
},
form:[
{
"type": "section",
"notitle": false,
"items": [
"date1"
]
}]

set "format":"date" in form

i set schema and form like that ,but it not effect, get the value "birthday": "5 January, 2016",not format like 'yyyy-mm-dd'

schema 
"birthday": {
                    "title": "date select",
                    "type": "string",
                    "format": "date",
                },

form 
{
                "key": "birthday",
                "minDate": "2014-06-20",
                "format": "yyyy-mm-dd",
                "default": new Date()
            }

Form does not render with only datepicker fields.

Forms do not render if only datepicker fields exist.

The following does not render

//schema
{
  "type": "object",
  "properties": {
    "date_complete": {
      "type": "string",
      "required": true,
      "format": "date"
    },
    "close_date": {
      "type": "string",
      "required": true,
      "format": "date"
    }
  }
}

//form
[
  {
    "key": "date_complete",
    "title": "Completed Date",
    "type": "datepicker",
    "readonly": false,
    "description": "Please Supply The Date This Task Was Completed.",
    "format": "mm/dd/yyyy"
  },
  {
    "key": "close_date",
    "title": "Close Date",
    "type": "datepicker",
    "readonly": false,
    "description": "Please Supply The Close Date.",
    "format": "mm/dd/yyyy"
  }
]

If I add a basic text field into the mix the form renders fine.

//schema
{
  "type": "object",
  "properties": {
    "date_complete": {
      "type": "string",
      "required": true,
      "format": "date"
    },
    "close_date": {
      "type": "string",
      "required": true,
      "format": "date"
    },
    "basicfield": {
      "type": "string"
    }
  }
}
//form
[
  {
    "key":"date_complete",
    "title": "Completed Date",
    "type": "datepicker",
    "readonly": false,
    "description": "Please Supply The Date This Was Completed.",
    "format": "mm/dd/yyyy",
    "required": true
  },{
    "key": "close_date",
    "title": "Close Date",
    "type": "datepicker",
    "readonly": false,
    "description": "Please Supply The Close Date.",
    "format": "mm/dd/yyyy",
    "required": true
  },
  {
    "key":"basicfield",
    "title": "basicfield"
  }
]

Any ideas?

Redrawing the form works but seems like a hack.

        let setScopesASF = doc =>{
          $scope.form   = doc.form;
          $scope.schema = doc.schema;

          $timeout(100, ()=>$scope.$broadcast('schemaFormRedraw'));
        };

Date picker field shows today's date when editing form data

I have this date picker implemented on a form who's data is saved and can then be edited at a later time. When I first load the form with no data, no date is displayed in the date picker field, I can pick a date with the date picker which then displays in the field, and save the data. When I come back to the form to edit the data, the date picker field shows today's date instead of the date contained in the model. When I save the form data without modifying the form, the date is in fact the correct date from the model, it is just not being displayed in the date picker field. Any ideas on why this is happening?

min/max date $watch continuously

Common use case is to have two pickers to specify start and end dates, where end date cannot be before the start date. Doesn't it make sense to keep watching for min/max date changes?

DatePicker DEMO

Hello,

i am searching a demo code for this module without success!!!

So i write this plunker

http://plnkr.co/edit/mjyd99

But i haven't any datepicker popup.

Is it ok? Where am I doing wrong?

King regards

Put repo to npm registry

Hi,

Would be great to do npm i angular-schema-form-datepicker because I am not using bower.

Best

Datapicker ignores htmlClass completly

It seems like the functionality from the angular-schema isn't completely passed through.
The htmlClass is ignored by the datepicker form field when the html is generated. But the code for the adjacent field is created as expected.

Any advice to get this working quickly?

{
    'type': 'section',
    'htmlClass': 'row',
    'items': [
        {'key': 'recentExam', 'format': 'mm-dd-yyyy', 'htmlClass': 'col-sm-6'},
        {'key': 'examPurpose', 'htmlClass': 'col-sm-6'}
    ]
},

This is the resulting html: http://postimg.org/image/xprmfqz6r/

Date Picker won't show up in FormController

I need to now when a field is dirty ($dirty, $pristine), but in the case of DatePicker it doesn't show in FormController object, in the example myForm:

    <form name="myForm"
        sf-schema="schema" sf-form="form" sf-model="model"
        ng-submit="onSubmit(myForm)" novalidate>
    </form>

Missing main-section in package.json

Making no PR as this applies to the color- and fontpicker as well and is such an easy fix.

The problem is that there is no main entry point defined in the package.json, so for example for jspm, there has to be a package override do define it.

DatePicker in Array

How can I use a DatePicker, if I´m using an array?
The problem is that is duplicating the data in all imputs, can anyone help me?

image

form:{ "key": "doc", "add": null, "remove": null, "items": [ { "key": "doc[].docDate", "notitle": true, "format": "dd-mm-yyyy", "fieldHtmlClass": "fechaFichaFinal", "placeholder": "dd-mm-yyyy" }]

Field isn't marked as success

Hi! Could you change:

 <div class="form-group..." ng-class="..">

with:

<div class="form-group..." ng-class="{'has-error': form.disableErrorState !== true && hasError(), 'has-success': form.disableSuccessState !== true && hasSuccess(), 'has-feedback': form.feedback !== false}">

[Feature Request] Field Addons / Inline Forms

We'd like to be able to add icons / glyphs / etc. in input-group-addons to the forms as described here:
ASF Issue 273.

If we implemented this for -datepicker and submitted a pull request, would the maintainers be amenable to merging it? The goal is to be able to attach an icon to the field like so:

screen shot 2015-02-27 at 3 57 30 pm

Incorrect date input style when it is disabled

When a date input has the disabled state, the background is not changed.

The problem comes from the datepicker.html:

<input ng-show="form.key"
       style="background-color: white"

Even if the component is disabled, the background color keeps as white, instead of changing to CSS classes ".form-control[disabled], .form-control[readonly], fieldset[disabled]"

question regarding ng-model="$$value$$"

Since the $$value$$ isn't on the controller scope, what the heck is it?

I'm trying to adjust this $$value$$ from a controller scope I created to wrap a file upload field I'm making , and being able to put stuff in $$value$$ is my missing link.

Difficult to select Date of Birth

Though this add-on has an elegant ui, it is not easy to select a date of birth since you have to click several times. It will be nice to have some drill down feature for the year.

Thanks.

Date Range in Filter

Hi,

as you know, the datepicker is also used as a filter in the list view of angular-schema-form.
Problem here: Barely anyone ever wants to filter for one special date.
The most common use-case is filter for a date range (i.e. I want to see all Users who logged in during the last week).

Is there already support for this?
If not, what would be best practise to build it?

onChange not supported

Hello,

I'm trying to use the "onChange" (from the standard option of angular-schema-form)
but the function is never called :

$scope.form = [
   {
    key: "start_date",
    format: "dd-mm-yyyy",
    onChange: function(modelValue,form) {
      console.log("start_date =", modelValue);
    }
   },
 ];

Angular formatters vs Angular parsers

TL;DR

angular-schema-form validates (with tv4) what's visible in the view. angular-schema-form-datepicker converts the dates to ISO8601 format (which json-schema supports) but does not change what is in the view. Because of this, when dates in the form are validated against the json schema (using the view value) validation can fail because it does not conform to the schema.

PROBLEM

Pickadate uses it's own localisations to convert the date (object) that the user picks to a string, which is displayed in the form input on-screen. For example, right now if I select 16th September 2014, because of my locale I will see "16 September, 2014" in my form.

The date format supported by json-schema is ISO8601 (eg. yyyy-mm-dd), so angular-schema-form-datepicker adds an angularjs formatter function (eg. ngModel.$formatters.push(fn)) to datepicker fields, which converts the date selected to a ISO8601 string, and then sets the formatted string on the underlying ngModel. This is the value that developers will see, and usually submit to an API (which presumably defines the json schema used for validation).

So far, so good.

angular-schema-form adds an angularjs $parser function to the ngModel (parser functions are called when an input changes), which calls tv4 and validates that single field. BUT... $parsers get sent the view value, not the model value (e.g. "16 September, 2014" not "2014-09-16"). Because of this angular-schema-form-datepicker is validating what is visible in the view against the json schema, even though this is not what will be submitted to the api. For example, if a pattern is set in the schema for a date-time field, it will fail validation unless the pickadate locale and the json-schema pattern match. Currently this is only an issue if there's no pattern set for the date-time in the schema, but it's conceivable that tv4 might change (in the future) to validate that date-time fields conform to ISO8601.

SUMMARY

angular-schema-form itself never uses angularjs formatters to convert values - all other form types in angular-schema-form save to the model exactly what is visible in the view. angular-schema-form-datepicker is the only place I have found where the view value is different from the model value, which is why I've raised the problem here.

I believe that angular-schema-form should be validating the value from the model, not the view, because it's the model that will be submitted to the server (and that needs to conform to json-schema). It's also possible to imagine other add-ons in the future which will use formatters.

Any Timepicker plans?

Is there any intention to have this add-on provide a time-picker as well since it uses pickadate.js?

Default date

scope.form = [
{
"key": "birthDate",
"minDate": "1995-09-01",
"maxDate": new Date(),
"format": "yyyy-mm-dd"
}
]

above example is there any possible to pass the default today date.
like
scope.form = [
{
"key": "birthDate",
"minDate": "1995-09-01",
"maxDate": new Date(),
"format": "yyyy-mm-dd"
"default":new Date()
}
]

Random default language

This may be by intent or my own ignorance about how to set the language - but the default language seems to vary unpredictably. In the kitchen sink demo it is Dutch even though the rest of the demo is English and the default for bootstrap-datepicker is en. Running on my server it is in German which is doubly odd.

question: how to pass options to pickadate ?

If I wanted to pass the following options :

$('.datepicker').pickadate({
    labelMonthNext: 'Go to the next month',
    labelMonthPrev: 'Go to the previous month',
    labelMonthSelect: 'Pick a month from the dropdown',
    labelYearSelect: 'Pick a year from the dropdown',
    selectMonths: true,
    selectYears: true
})

how would I do it

  1. for a single field in a form
  2. to all date fields (default global option)

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.