Skip to content

Commit

Permalink
Handle initialisers from loadDefaults correctly #219
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Jan 8, 2024
1 parent 9ffaed8 commit 6f7e449
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion grails-app/assets/javascripts/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ function orEmptyArray(v) {
self([]);
}
if (data === undefined) {
self.loadDefaults();
initialisers = initialisers.concat(self.loadDefaults());
}
else {
_.each(data, function (row, i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,13 @@ class ModelJSTagLib {
boolean userAddedRows = Boolean.valueOf(viewModel?.userAddedRows)
def defaultRows = []
model.defaultRows?.eachWithIndex { row, i ->
defaultRows << INDENT*5 + "rowInitialisers.push(${ctx.propertyPath}.${model.name}.addRow(${row.toString()}));"
defaultRows << INDENT*5 + "rowInitialisers = rowInitialisers.concat(${ctx.propertyPath}.${model.name}.addRow(${row.toString()}));"
}
def insertDefaultModel = defaultRows.join('\n')

// If there are no default rows, insert a single blank row and make it available for editing.
if (attrs.edit && model.defaultRows == null) {
insertDefaultModel = "rowInitialisers.push(${ctx.propertyPath}.${model.name}.addRow());"
insertDefaultModel = "rowInitialisers = rowInitialisers.concat(${ctx.propertyPath}.${model.name}.addRow());"
}

out << """var context = _.extend({}, context, {parent:self, listName:'${model.name}'});"""
Expand Down

0 comments on commit 6f7e449

Please sign in to comment.