Search code examples
meteormeteor-autoform

Where to put SimpleSchema.RegEx.Url2 so it is usable in multiple simple schemas


New to Meteor.

I'd like to extend SimpleSchema.RegEx with an additional RE so that it is available in multiple schemas. I've tried putting

SimpleSchema.RegEx.Url2 = /.../;

in lib, collections, client, and server but none seems to work.

Need some clues.

Thanks.


Solution

  • In my case I had my collections defined in

    `app\lib\collections\simple_schema.js`
    

    placing the RE in a file in that directory worked sometimes but not always.

    The underlying problem was load order. For collections in files with names that sort AFTER simple_schema.js, the additional RE was available. For those with names that sort BEFORE simple_schema.js, the RE was not available.

    Placing simple_schema.js in

    `app\lib\collections\simple_schema_extensions\simple_schema.js` 
    

    resolves the issue as Meteor load order is depth first (well documented).