You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
option for ignore validation on fields with 'allowNull=true' #270
Would be nice to have an option to ignore the validation settings if the field value is null with the allowNull parameter set.
Another way would be come up with custom validation methods (for example 'allowNullOrIsEmail') but that would mean that we need access to the other validation functions (to reuse em).
This is the same as #118, and it's not clear why that one is closed. I'd like to see this implemented, but I don't think it should even be an option. If allowNull is true, clearly you want to allow null. If it's not null, only then should the other validations happen. As for the other issue I commented on tonight, I'll offer a small donation as bounty if this is addressed soon.
So, for instance, if a string field has allowNull: true, but also validate: len: 1, an empty string "" should fail, a string "string" should pass, and null should pass.
@tremby and @janmeier Hello and sorry to bring this up after so many years, but I would like to point out that this should be an opt-out option instead of a forced behaviour.
@tremby said: "I don't think it should even be an option. If allowNull is true, clearly you want to allow null."
This is being a problem for me, because I want to allow null depending on other fields:
myField: {validate: {custom(value){if(value===null&&!foobar(this.otherField1,this.otherField2)){thrownewError("myField can't be null when otherField1 and otherField2 satisfy property X");}}}}
But with the changes made in #601, if I do allowNull: true, it is always allowed. If I do allowNull: false, it is never allowed, and I can't escape this... (if I omit it, it defaults to true)
This should be an option (that comes enabled, of course), so I can disable it for myField in my case... It's very specific but maybe others will encounter the same problem.
Activity
tremby commentedon Feb 26, 2013
This is the same as #118, and it's not clear why that one is closed. I'd like to see this implemented, but I don't think it should even be an option. If allowNull is true, clearly you want to allow null. If it's not null, only then should the other validations happen. As for the other issue I commented on tonight, I'll offer a small donation as bounty if this is addressed soon.
janmeier commentedon Feb 26, 2013
Agree, this should be implemented. I think we can safely infer that if a field allows null it should not be validated if it contains a null value.
tremby commentedon Feb 27, 2013
So, for instance, if a string field has allowNull: true, but also validate: len: 1, an empty string "" should fail, a string "string" should pass, and null should pass.
janmeier commentedon May 9, 2013
Implemented in #601
papb commentedon Feb 28, 2018
@tremby and @janmeier Hello and sorry to bring this up after so many years, but I would like to point out that this should be an opt-out option instead of a forced behaviour.
@tremby said: "I don't think it should even be an option. If allowNull is true, clearly you want to allow null."
This is being a problem for me, because I want to allow null depending on other fields:
But with the changes made in #601, if I do
allowNull: true, it is always allowed. If I doallowNull: false, it is never allowed, and I can't escape this... (if I omit it, it defaults to true)This should be an option (that comes enabled, of course), so I can disable it for
myFieldin my case... It's very specific but maybe others will encounter the same problem.What do you think?
Thanks a lot!
tremby commentedon Mar 5, 2018
I hadn't considered a use case like that. But I am going to bow out of discussion -- I haven't used Sequelize in years.
papb commentedon Mar 6, 2018
@tremby Thank you for responding! No problem.
I opened a new issue about this: #9143