Comments (6)
@brianpkelley I'm on holiday this week but I will try to add this change next week, thanks for taking the time to provide the info! :)
from angular-schema-form-material.
md-datepicker
returns a Date object, and angular-schema-form wants a string. Without calling one of the toString methods on it, it won't matter what we pass to it.
How I fixed it was:
Add this conditional to the /angular-schema-form/src/services/validator.js
around line 39
// Date values
if ( schema.type === 'string' && schema.format === 'date' ) {
if ( value === null ) {
value = undefined;
} else {
if ( typeof value.toISOString === 'function' ) {
value = value.toISOString();
}
}
}
from angular-schema-form-material.
In testing found a bug in the date check, I've updated my comment above to reflect the change.
from angular-schema-form-material.
@brianpkelley Great! Thanks! I will try it!
from angular-schema-form-material.
The fix above only works dates outside of arrays (i'd say average operation) if they're inside of an array
type tv4 is handling the validation and we can't convert the angular <input type="date"
directive which is passing back a Date
object.
To fix this, I hackishly created another date format/builder with "type": "object"
and "format": "date"
and applied the tv4 custom format to validate the date. This way tv4 is looking for an object (check) and the custom format validates it.
// ISO Format - 2016-08-02T17:03:18.608Z - new Date().toISOString()
var dateFormat = /^[0-9]{4,}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]+|)(?:[+-][0-9]{2}:?(?:[0-9]{2}|)|Z)$/;
// Standard Format - Tue Aug 02 2016 12:03:59 GMT-0500 (CDT) - new Date().toString()
var mdDateFormat = /^(:?[A-Z][a-z]{2}\s){2}\d{1,2}\s\d{4}\s(:?\d{2}\:?){3}\s[A-Z]{3}\-\d{4}\s\([A-Z]{3}\)$/;
var formats = {
date: function (value) {
if ( value && typeof value !== 'string' && value.toISOString ) {
value = value.toISOString() || '';
}
if (dateFormat.test(value) || mdDateFormat.test(value) ) {
return null;
}
return 'A valid date expected';
}
};
tv4.addFormat( 'date', formats.date );
function dateObjectDefault(name, schema, options) {
if (schema.type === 'object' && (schema.format === 'date' || schema.format === 'date-time')) {
var f = schemaFormProvider.stdFormObj(name, schema, options);
f.key = options.path;
f.type = 'date';
options.lookup[sfPathProvider.stringify(options.path)] = f;
return f;
}
};
schemaFormProvider.defaults.object.unshift(dateObjectDefault);
from angular-schema-form-material.
@brianpkelley hey I am facing a same problem with datepicker.
After place the code above in material-decorator.js, build, and also changed the type object. I did well ?
Because if a use the datepicker and chose a date seems to be fine, but if a have the field required and don't chose any date I just received "Invalid type, expected object", so do I need to change the validator.js also ?
I appreciate any help.
from angular-schema-form-material.
Related Issues (20)
- angular-material: breaking formatting changes HOT 2
- Understanding how to present the user with the ng-message HOT 4
- Release NPM HOT 3
- Bower registry problem HOT 5
- Inacurate textarea maxlength error HOT 2
- Some elements cannot be flex containers HOT 1
- Error message issues - with fixes
- Checkbox not rendering correctly on load HOT 3
- How to extend this decorator HOT 2
- model with previus data not showing correctly HOT 4
- Form Action Buttons not responding to onClick HOT 2
- Validation error messages are not displayed.
- Inputs doesn't show model values until click in input HOT 1
- Form Action Button "onClick" not responding to method in component.
- md-datepicker
- md-select: dynamic options
- md-autocomplete HOT 6
- Flex layout
- md-textarea: add rich text editor support (add-on?)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-schema-form-material.