Skip to content

Commit

Permalink
Merge pull request #21 from smessie/default-value-context-form
Browse files Browse the repository at this point in the history
Set a default value for `context.form` instead of throwing an error
  • Loading branch information
danielbeeke authored Aug 24, 2022
2 parents 7fcfe16 + 47020fd commit c7de57a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/FormDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class FormDefinition extends EventTarget implements CoreComponent {
private formAsTextOrUrl: string
private sourceDefinitionCompacted: object = {}
private sourceDefinitionExpanded: Array<any>
public context = { form: null }
public context = { form: '' }
public ready: boolean = false
public chain = new Map()
public chainReferences = new Map()
Expand Down Expand Up @@ -54,7 +54,9 @@ export class FormDefinition extends EventTarget implements CoreComponent {

this.sourceDefinitionCompacted = ttl2jsonld(definitionTurtle)
Object.assign(this.context, this.sourceDefinitionCompacted['@context'])
if (!this.context.form) throw new Error('The prefix form was not found in the form definition.')
if (!this.context.form) {
this.context.form = 'http://rdf.danielbeeke.nl/form/form-dev.ttl#';
}
if (!this.sourceDefinitionCompacted['@graph']) throw new Error('Missing fields inside form definition')
this.sourceDefinitionExpanded = JsonLdProxy(await JsonLdExpand(this.sourceDefinitionCompacted), this.context, {
'_': (value) => Language.multilingualValue(value, 'ui')
Expand Down Expand Up @@ -180,4 +182,4 @@ export class FormDefinition extends EventTarget implements CoreComponent {
}
return bindings
}
}
}

0 comments on commit c7de57a

Please sign in to comment.