How to pass value into the custom message (Simpl Schema)?


#1

I want to pass any values into the custom message

   issueDate: {
        type: String
    },
    expiryDate: {
        type: String
        custom: function () {
            if (this.value < this.field('issueDate').value) {
                // Want to pass this.field('issueDate').value into message below
                return 'expiryDateGt';
            }
        }
    },

// Custom message
SimpleSchema.messages({
    "expiryDateGt": "[label] must be greater then issue date [value].",
});

#2

Did yo end up working out how to do this? I’ve read and reread autoforms, simple schema section about custom validation messages and for the life of me can’t work out how to replace the default “XXXXX failed regular expression validation” message.

To clarify, the examples seem to want you to declare a global message type and then perform your own custom validation by a custom function and then use your global message.
However, all I want to to is piggy back off the existing regex validation but overwrite the error message for that one field in that one schema.

EDIT:
I finally comprehended the doco:

Schema.<schemaName>.messages({'regEx expiryDate': [{msg:'<custom message here>'}]})

and also realised you were asking a different question to me, sorry for the hijack, at least it bumped your question :wink: