mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 22:13:26 +09:00
refactor: form binding validation (#38832)
Make "form-fetch-action" highlight the invalid field as "error"
This commit is contained in:
@@ -26,7 +26,7 @@ func Bind[T any](_ T) http.HandlerFunc {
|
||||
return func(resp http.ResponseWriter, req *http.Request) {
|
||||
theObj := new(T) // create a new form obj for every request but not use obj directly
|
||||
data := middleware.GetContextData(req.Context())
|
||||
binding.Bind(req, theObj)
|
||||
_ = binding.Bind(req, theObj) // no need to handle "errs" here, the errors are handled in our middleware.Validate (binding.go)
|
||||
SetForm(data, theObj)
|
||||
middleware.AssignForm(theObj, data)
|
||||
}
|
||||
@@ -37,6 +37,10 @@ func SetForm(dataStore reqctx.ContextDataProvider, obj any) {
|
||||
dataStore.GetData()["__form"] = obj
|
||||
}
|
||||
|
||||
func IsFormSet(dataStore reqctx.RequestDataStore) bool {
|
||||
return dataStore.GetData()["__form"] != nil
|
||||
}
|
||||
|
||||
// GetForm returns the validate form information
|
||||
func GetForm[T any](dataStore reqctx.RequestDataStore) T {
|
||||
form, ok := dataStore.GetData()["__form"].(T)
|
||||
|
||||
Reference in New Issue
Block a user