func (self SetModelValueControllerBase) SetValue(value string, ctx *Context, metaData *model.MetaData, form *Form) error {
	mdl, ok := metaData.ModelValue()
	if !ok {
		panic("metaData must be model.Value")
	}
	mdl.SetString(value)
	return nil
}
Exemple #2
0
func (self *Form) IsFieldRequired(metaData *model.MetaData) bool {
	if val, ok := metaData.ModelValue(); ok && val.Required(metaData) {
		return true
	}
	selector := metaData.Selector()
	wildcardSelector := metaData.WildcardSelector()
	return utils.StringIn(selector, self.RequiredFields) || utils.StringIn(wildcardSelector, self.RequiredFields)
}
Exemple #3
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
}
Exemple #4
0
func (self *Form) IsFieldRequired(field *model.MetaData) bool {
	if val, ok := field.ModelValue(); ok && val.Required(field) {
		return true
	}
	return field.SelectorsMatch(self.RequiredFields)
}