html5 - AngularJS Initialize a dynamic date field to JavaScript Date -
i building dynamic form , using html5 date input fields of type date. struggling date input display date, , have come conclusion value has javascript date or date not display. if wrong on that, please correct me because doesn't seem should requirement. because fields dynamic can't initialize specific fields date, created directive convert javascript date.
angular.module( 'convertdate-directive', [] ) .directive('convertdate', function( $parse ) { return { restrict: "a", link: function( scope, element, attrs ) { var fieldmodel = $parse( attrs.ngmodel ); var fieldvalue = fieldmodel( scope ); fieldmodel.assign( scope, new date( fieldvalue ) ); } }; }); here date input, rendered if field of type date:
<input type="date" ng-if="field.type == 'date'" dynamic-model="field.name" ng-model="field.name" name="field.name" max="{{field.maxvalue | date : 'yyyy-mm-dd'}}" min="{{field.minvalue | date : 'yyyy-mm-dd'}}" ng-required="field.required" ng-model-options="{ updateon: 'blur' }" convert-date class="form-control"> the problem directive triggers $watch have on object in controller, determines whether changes have been made , save needed.
my watch code:
$scope.$watch( 'application.' + resource.name, function( newvalue, oldvalue ) { if ( newvalue !== oldvalue ) { resource.changed = true; } }, true ); is there way suppress change event in scenario? or, there better way initialize html5 date field? looking ideas. thanks!
a date input doesn't require value set date object. requires in iso format. see question/answer more details: pre-populating date input field javascript
Comments
Post a Comment