Example #1
0
func (self *Ref) Validate(metaData *model.MetaData) error {
	if self.CollectionName == "" {
		return errs.Format("Missing CollectionName")
	}
	length := len(self.ID)
	if length != 0 && length != 12 {
		return errs.Format("Invalid ObjectId length %d", length)
	}
	if self.Required(metaData) && self.IsEmpty() {
		return model.NewRequiredError(metaData)
	}
	return nil
}
Example #2
0
func (self *validateAndFormLayoutStructVisitor) validateField(field *model.MetaData) error {
	if value, ok := field.ModelValue(); ok {
		err := value.Validate(field)
		if err == nil && value.IsEmpty() && self.form.IsFieldRequired(field) {
			err = model.NewRequiredError(field)
		}
		if err != nil {
			self.fieldValidationErrors = append(self.fieldValidationErrors, err)
		}
		return err
	}
	return nil
}
Example #3
0
func (self *Ref) Validate(metaData *model.MetaData) error {
	if self.CollectionName == "" {
		return errs.Format("Missing CollectionName")
	}
	length := len(self.ID)
	if length != 0 && length != 12 {
		return errs.Format("Invalid ObjectId length %d", length)
	}
	if self.Required(metaData) && self.IsEmpty() {
		return model.NewRequiredError(metaData)
	}
	if ok, err := self.CheckID(); !ok {
		if err != nil {
			return err
		}
		return errs.Format("Invalid mongo.Ref. No document with ID %s in collection %s", self.ID, self.CollectionName)
	}
	return nil
}
Example #4
0
func (self *BlobRef) Validate(metaData *model.MetaData) error {
	if self.Required(metaData) && self.IsEmpty() {
		return model.NewRequiredError(metaData)
	}
	return nil
}