Created
April 8, 2015 18:19
-
-
Save jquense/7cd0757b783acaa65f77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// there are a few methods that you need to implement/override to create a new type | |
// The main one is `_coerce`, which passing in the raw value and returns the type back. | |
// _coerce should not throw errors, and should return the default invalid object for a type if it exists (NaN, etc) | |
//here is the date `_coerce()` (I need to change it to return an InvalidDate instead of null) | |
_coerce(value) { | |
if(value == null ) return value | |
if(isDate(value) ) return new Date(value) | |
value = isoParse(value) | |
return value ? new Date(value) : null | |
} | |
// create new schema Type | |
var myDateType = yup.date.extend({ | |
coerce(value){ | |
var baseVal = yup.date.prototype._coerce.call(this,val) | |
//do whatever if you didn't get a date | |
} | |
}) | |
//mutate existing | |
var baseDateCoerce = yup.date.prototype._coerce; | |
yup.date.prototype._coerce = function(value){ | |
baseDateCoerce.call(this) | |
// blah blah | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment