work on #470 and fix miror JS issue when choose targets on compare and pull

This commit is contained in:
Unknwon 2015-10-29 21:09:48 -04:00
parent 706b0f72e2
commit 7d72c8333e
7 changed files with 26 additions and 18 deletions

View file

@ -181,7 +181,7 @@ func AssignForm(form interface{}, data map[string]interface{}) {
}
}
func getSize(field reflect.StructField, prefix string) string {
func getRuleBody(field reflect.StructField, prefix string) string {
for _, rule := range strings.Split(field.Tag.Get("binding"), ";") {
if strings.HasPrefix(rule, prefix) {
return rule[len(prefix) : len(rule)-1]
@ -191,15 +191,19 @@ func getSize(field reflect.StructField, prefix string) string {
}
func GetSize(field reflect.StructField) string {
return getSize(field, "Size(")
return getRuleBody(field, "Size(")
}
func GetMinSize(field reflect.StructField) string {
return getSize(field, "MinSize(")
return getRuleBody(field, "MinSize(")
}
func GetMaxSize(field reflect.StructField) string {
return getSize(field, "MaxSize(")
return getRuleBody(field, "MaxSize(")
}
func GetInclude(field reflect.StructField) string {
return getRuleBody(field, "Include(")
}
// FIXME: struct contains a struct
@ -260,6 +264,8 @@ func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaro
data["ErrorMsg"] = trName + l.Tr("form.email_error")
case binding.ERR_URL:
data["ErrorMsg"] = trName + l.Tr("form.url_error")
case binding.ERR_INCLUDE:
data["ErrorMsg"] = trName + l.Tr("form.include_error", GetInclude(field))
default:
data["ErrorMsg"] = l.Tr("form.unknown_error") + " " + errs[0].Classification
}