No save if *any* errors found

7 views
Skip to first unread message

Nathan Hornby

unread,
Jul 29, 2015, 5:59:10 PM7/29/15
to Mongoose Node.JS ODM

I'm assuming this is intended behaviour and not a bug - but I'm running into an issue using mongoose to validate a form's input, as on save it appears to discard *all* fields if one or more fields fails to validate. i.e. for the save to trigger there needs to be no errors on any of the input.

Is there a way that I can use inline validation (`match`, specifically), but still save fields that *do* validate correctly? Or am I going to have to handle all validation before it hits mongoose and only pass in the fields that I know will validate?

Basically my scenario is a settings page. So if a user changes a load of settings but only has one field with an issue, I want to save all the other fields, and only not save the one with the issue.

Raz Goldin

unread,
Aug 22, 2015, 11:38:19 AM8/22/15
to Mongoose Node.JS ODM
Hi:

From what I understand of what you're saying: 'I want to save the rest of the fields when one of the fields failed to validate.'

I would say that since you are talking about settings there probably are DEFAULT settings that each person has, and you want them to be able to change those default settings. If they don't change anything then let it keep the default settings and if they specified that setting then that will be stored in the database? You can have default values which are valid and that way as long as they keep them blank it will store them for the default values.

Otherwise, if you have 1 field that is invalid among 20 it won't save.
Reply all
Reply to author
Forward
0 new messages