Sunday, 15 May 2011

javascript - model validation on server side in locomotivejs -



javascript - model validation on server side in locomotivejs -

i want know if there function check if model valid on server side ,i using locomotivejs on express.

here model schema

var billschema = new schema({ brandid:schema.types.objectid, modelno:{ type: string, required: true }, billno:{ type: string, required: true }, years:number, months:number, })

in controller , receiving values view.

var bill=new bill(); bill.categoryid=self.param('categoryid'); bill.brandid=self.param("brandid"); bill.modelno=self.param("model"); bill.billno=self.param("billno"); if(bill.categoryid!="" && bill.brandid!="" && bill.modelno!="" && bill.years!="") { // code save values db }

is there way avoid validation

if(bill.categoryid!="" && bill.brandid!="" && bill.modelno!="" && bill.years!="")

with modelstate.isvalid in .net mvc

thanks in advance...

guys got problem resolved. mongoose provides validate function this.

bill.validate(function (err) { if(err) {// handle error} else {// save db.}

thanks...

javascript express locomotivejs

No comments:

Post a Comment