Skip to content

Commit

Permalink
fix(admin): fixed custom new form
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Sep 15, 2020
1 parent 49ac2aa commit 4dac781
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 9 additions & 3 deletions plugins/admin/modules/table/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func NewDefaultTable(cfgs ...Config) Table {
BaseTable: &BaseTable{
Info: types.NewInfoPanel(cfg.PrimaryKey.Name),
Form: types.NewFormPanel(),
NewForm: types.NewFormPanel(),
Detail: types.NewInfoPanel(cfg.PrimaryKey.Name),
CanAdd: cfg.CanAdd,
Editable: cfg.Editable,
Expand All @@ -72,6 +73,9 @@ func (tb *DefaultTable) Copy() Table {
Form: types.NewFormPanel().SetTable(tb.Form.Table).
SetDescription(tb.Form.Description).
SetTitle(tb.Form.Title),
NewForm: types.NewFormPanel().SetTable(tb.Form.Table).
SetDescription(tb.Form.Description).
SetTitle(tb.Form.Title),
Info: types.NewInfoPanel(tb.PrimaryKey.Name).SetTable(tb.Info.Table).
SetDescription(tb.Info.Description).
SetTitle(tb.Info.Title).
Expand Down Expand Up @@ -988,11 +992,13 @@ func (tb *DefaultTable) DeleteData(id string) error {

func (tb *DefaultTable) GetNewFormInfo() FormInfo {

if len(tb.Form.TabGroups) == 0 {
return FormInfo{FieldList: tb.Form.FieldsWithDefaultValue(tb.sql)}
f := tb.GetActualNewForm()

if len(f.TabGroups) == 0 {
return FormInfo{FieldList: f.FieldsWithDefaultValue(tb.sql)}
}

newForm, headers := tb.Form.GroupField(tb.sql)
newForm, headers := f.GroupField(tb.sql)

return FormInfo{GroupFieldList: newForm, GroupFieldHeaders: headers}
}
Expand Down
9 changes: 4 additions & 5 deletions plugins/admin/modules/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,14 @@ func (base *BaseTable) GetForm() *types.FormPanel {
}

func (base *BaseTable) GetNewForm() *types.FormPanel {
return base.Form.SetPrimaryKey(base.PrimaryKey.Name, base.PrimaryKey.Type)
return base.NewForm.SetPrimaryKey(base.PrimaryKey.Name, base.PrimaryKey.Type)
}

func (base *BaseTable) GetActualNewForm() *types.FormPanel {
f := base.GetNewForm()
if len(f.FieldList) == 0 {
return base.GetForm()
if len(base.NewForm.FieldList) == 0 {
return base.Form
}
return f
return base.NewForm
}

func (base *BaseTable) GetCanAdd() bool {
Expand Down

0 comments on commit 4dac781

Please sign in to comment.