Meteor-Community-Packages / meteor-simple-schema

Meteor integration package for simpl-schema
https://github.com/Meteor-Community-Packages/meteor-simple-schema
MIT License
920 stars 162 forks source link

Overwriting SimpleSchema regEx messages #720

Closed vfonic closed 6 years ago

vfonic commented 6 years ago

I just realized that doing this:

SimpleSchema.messages({
  regEx: [{ exp: SimpleSchema.RegEx.Url, msg: 'URL is not a valid URL' }],
});

...removes all other regEx validation error messages and I'm getting a lot of "Unknown validation error" for, for example SimpleSchema.RegEx.Email. Is there a way to append/replace only a single exp?

brooksbecton commented 6 years ago

I did a Code Pen where I copied the default messages and "extended" in a new message. Edited: I see it now. I'm dumb. The codepen shows that is is not spreading correctly

brooksbecton commented 6 years ago

Gotta another pen here that shows how mergeWith can combine the two.

vfonic commented 6 years ago

Thanks @brooksbecton!

What do you suggest would be the best way to use this in my project's code? Should I just directly manipulate SimpleSchema._globalMessages?

Do you think this should be added to the simple-schema code itself? I'm really swamped right now, but if I find some time I could submit a PR.

brooksbecton commented 6 years ago

According to the README NOTE: "v2" of this package is an NPM package. Please use the NPM package even in Meteor apps. This Meteor package will get only critical fixes...

This seems important, but it is up to the maintainers on whether this is a critical fix or not.

The npm package for simple-schema-js is using extend which does properly spread the default messages with the new messages. So if you can migrate over to it, that would probably be best.


Also wanted to note here that this repo is using underscore.js not lodash.

aldeed commented 6 years ago

The Meteor SimpleSchema package is no longer maintained other than critical fixes to keep it running with each latest Meteor release. Closing non-critical issues in this repo. Anyone who cares about this may do one or more of the following: