ui: Handle default value

This commit is contained in:
nemunaire 2023-01-18 17:30:06 +01:00
parent cc2583aa85
commit 299de072d0
2 changed files with 7 additions and 2 deletions

View File

@ -41,7 +41,7 @@ import (
type PowerdnsAPI struct {
ApiUrl string `json:"apiurl,omitempty" happydomain:"label=API Server Endpoint,placeholder=http://12.34.56.78"`
ApiKey string `json:"apikey,omitempty" happydomain:"label=API Key,placeholder=a0b1c2d3e4f5=="`
ServerID string `json:"server_id,omitempty" happydomain:"label=Server ID,placeholder=localhost,default=localhost,description=Unless you are using a specially configured reverse proxy leave blank"`
ServerID string `json:"server_id,omitempty" happydomain:"label=Server ID,placeholder=localhost,description=Unless you are using a specially configured reverse proxy leave blank"`
}
func (s *PowerdnsAPI) NewDNSServiceProvider() (providers.DNSServiceProvider, error) {
@ -51,6 +51,10 @@ func (s *PowerdnsAPI) NewDNSServiceProvider() (providers.DNSServiceProvider, err
"serverName": s.ServerID,
}
if s.ServerID == "" {
config["serverName"] = "localhost"
}
return providers.CreateDNSProvider(s.DNSControlName(), config, nil)
}

View File

@ -5,7 +5,8 @@ export function fillUndefinedValues(value: any, spec: Field) {
let vartype = spec.type;
if (vartype[0] == "*") vartype = vartype.substring(1);
if (vartype == "[]uint8") value[spec.id] = "";
if (spec.default !== undefined) value[spec.id] = spec.default;
else if (vartype == "[]uint8") value[spec.id] = "";
else if (vartype.startsWith("[]")) value[spec.id] = [];
else if (vartype != "string" && !vartype.startsWith("uint") && !vartype.startsWith("int") && vartype != "time.Duration" && vartype != "net.IP") value[spec.id] = { };
}