Comments (8)
@tehhowch I'm not familiar with date validations. Can you post some examples how you use them? Maybe we can figure out how to mitigate the pain.
For reference the PR that introduced the changes: adopted-ember-addons/ember-validators#100
from ember-cp-validations.
I saw that PR, yes. (I also noticed that the changes to make the tests work completely ignored the point and purpose of some of the tests, e.g. every test around 'now'
was reimplemented without changing the name-i.e. purpose-of the test, e.g. https://github.com/rwwagner90/ember-validators/pull/100/files?diff=split&w=0#diff-1b3840443c6b8c137c8790bb3a5e573b85ea331871438650849e8abf7b073d5fR120-R134)
The primary use case my team runs into is a validator that is defined in an internal addon that uses 'now', e.g.
const endDateInFutureValidation = {
onOrAfter: 'now',
format: SOME_FORMAT,
errorFormat: OTHER_FORMAT,
messageKey: 'validations.end.date.in.past',
};
// ...
const Validations = buildValidations({
// ... other validatons
endDate: validator('date', {
disabled: or('..conditions'),
...endDateInFutureValidation,
}),
})
and the goal is that users can't schedule something that is in the past. The upstream PR replaces usage of 'now'
with explicit calls to the current time (example), which has no guarantee in production code that it is still the current time when the validation is actually performed, especially if the user has a long session.
from ember-cp-validations.
I agree that the tests around the date validations got messy and should be revisited. Also the docs need an update.
Something I run into doing the updates was the fact that it's possible to have getter as options.
ember-cp-validations/tests/dummy/app/models/user-detail.js
Lines 14 to 18 in 9ab10fd
So in your case
const endDateInFutureValidation = {
get onOrAfter() {
return new Date();
},
format: SOME_FORMAT,
errorFormat: OTHER_FORMAT,
messageKey: 'validations.end.date.in.past',
};
should work.
from ember-cp-validations.
That could indeed work, but as I was investigating, I determined that PR to ember-validators also broke the expectations on format
- namely, that the input date should be in that format, and if not, a wrongDateFormat
error should be raised.
To unblock my team's apps, we have just completely stopped using the 'date'
validator shipped by this repo/ember-validators, because using it would have required changing how we do 'now', 'precision'
, and also required inserting another validator to handle required formats.
(There was also the issue that the upstream PR defaults all input parsing of dates to new Date(<string>)
, which is well-documented as something you should avoid due to the wide variety of implementation behaviors.)
from ember-cp-validations.
@tehhowch Did you use an inline validator to replace the date
validator? Would be great if we can document how people in the same situation can solve the problem...
from ember-cp-validations.
I extended the existing date validator and provided a fixed validate
method that still used moment
internally.
I think what could make sense is to provide two peer/optional dependencies, one for luxon and one for moment, and use the test
method to have the 'date'
validator use whichever has also been installed rather than the busted ember-validator version.
from ember-cp-validations.
@tehhowch do you mind sharing your solution here so others can use it?
from ember-cp-validations.
I'll need to reimplement it blind, so no promises on when I'll have free time to do that.
I also think there is perhaps more value to the approach I mentioned before, where library-specific validators (one for luxon, one for moment, etc.) are implemented and conditionally used. That would require the consumers to configure the add-on.
(Possibly those validators / customization belong in ember-validators instead, and we run into the issue of not wanting to auto-install all date libraries.)
from ember-cp-validations.
Related Issues (20)
- `getWithDefault` deprecation in Ember3.21
- Validation on model versus component HOT 1
- Has-many relationship propagates 'messages' property but not 'errors' property
- Validations including a has-many relationship broken when lazily evaluated
- Getting Unit Tests to Work HOT 3
- Assertion Failed with Embroider HOT 3
- Ember CP validation does not support ember octane with glimmer component HOT 4
- After update to ember 3.27.5 there is an error: Uncaught TypeError: (0 , _string.isHTMLSafe) is not a function HOT 8
- Ember Global deprecation warning due to old version of ember-cli-babel HOT 4
- Installing this addon breaks build on Ember 4 HOT 1
- Running ember-cp-validations using typescript
- Documentation site no longer exists HOT 1
- Release strategy HOT 27
- Setup release, changelog, etc according to the guidelines HOT 3
- Setup Docs HOT 1
- Multiple conditionally required fields validation
- Validations with EmberObject does not work? HOT 3
- 3.x Documentation link is down
- `Error: "EmberObject.create no longer supports.."` on Ember-4.12 addon - ONLY during embroider-safe scenario HOT 1
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 ember-cp-validations.