Skip to content

Commit 1a25f44

Browse files
committed
Merge branch 'hotfix/4.0.5' of https://github.com/AtlasOfLivingAustralia/ecodata-client-plugin into hotfix/4.0.5
2 parents fb3bbcf + b98ba4a commit 1a25f44

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

grails-app/taglib/au/org/ala/ecodata/forms/ModelJSTagLib.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ class ModelJSTagLib {
275275
out << INDENT*4 << "self.load${mod.name}(${value});\n"
276276
}
277277
else if (mod.dataType == 'species') {
278+
out << INDENT*4 << "if (data['${mod.name}']) {\n"
278279
out << INDENT*4 << "${ctx.propertyPath}['${mod.name}'].loadData(${value});\n"
280+
out << INDENT*4 << "}\n"
279281
}
280282
else if (mod.dataType == 'document') {
281283
out << INDENT*4 << "var doc = _.find(context.documents || [], function(document) { if (data['${mod.name}']) \n return document.documentId == data['${mod.name}'] || document.documentId == data['${mod.name}'].documentId ;\n else \n return false });"

src/test/groovy/au/org/ala/ecodata/forms/ModelJSTagLibSpec.groovy

+14
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ class ModelJSTagLibSpec extends Specification implements TagLibUnitTest<ModelJST
232232
compareWithoutWhiteSpace("data['test'].load(ecodata.forms.orDefault(data['test'],undefined));data['test'](ecodata.forms.orDefault(data['test'],undefined));", actualOut.toString())
233233
}
234234

235+
def "Input data is null/undefined checked before calling loadData() on SpeciesViewModel"() {
236+
setup:
237+
Map dataModel = [name:'test', dataType:'species']
238+
ctx.dataModel = dataModel
239+
ctx.propertyPath = 'self.data'
240+
ctx.attrs = [:]
241+
242+
when:
243+
tagLib.renderInitialiser(ctx)
244+
245+
then:
246+
compareWithoutWhiteSpace("if(data['test']){self.data['test'].loadData(ecodata.forms.orDefault(data['test'], {}));}", actualOut.toString())
247+
}
248+
235249
def "The lookup table data type is rendered correctly"() {
236250
setup:
237251
List lookupTable = [[input:'a', output:'1'], [input:'b', output:'2']]

0 commit comments

Comments
 (0)