diff --git a/angular/shared/form/field-andsvocab.component.ts b/angular/shared/form/field-andsvocab.component.ts index d3ad0c70f4..e47c3a2296 100644 --- a/angular/shared/form/field-andsvocab.component.ts +++ b/angular/shared/form/field-andsvocab.component.ts @@ -42,11 +42,17 @@ export class ANDSVocabField extends FieldBase { public andsService:ANDSService; public vocabId:string; + public disableCheckboxRegexEnabled:boolean; + public disableCheckboxRegexPattern:string; + public disableCheckboxRegexTestValue:string; constructor(options: any, injector: any) { super(options, injector); this.value = options['value'] || this.setEmptyValue(); this.vocabId = options['vocabId'] || 'anzsrc-for'; + this.disableCheckboxRegexEnabled = options['disableCheckboxRegexEnabled'] || false; + this.disableCheckboxRegexPattern = options['disableCheckboxRegexPattern'] || ""; + this.disableCheckboxRegexTestValue = options['disableCheckboxRegexTestValue'] || ""; this.andsService = this.getFromInjector(ANDSService); } @@ -124,7 +130,7 @@ export class ANDSVocabComponent extends SimpleComponent { repository: this.field.vocabId, endpoint: 'https://vocabs.ardc.edu.au/apps/vocab_widget/proxy/', fields:["label", "notation", "about"], - cache: false + cache: false }); this.field.componentReactors.push(this); } @@ -174,6 +180,9 @@ export class ANDSVocabComponent extends SimpleComponent { public onEvent(event) { switch(event.eventName) { case "select": + if(!this.isSelectionValid(event.node)){ + break; + } this.field.setSelected(this.getValueFromChildData(event.node), true); break; case "deselect": @@ -191,7 +200,11 @@ export class ANDSVocabComponent extends SimpleComponent { switch(event.eventName) { case "nodeActivate": if (currentState == undefined) { - currentState = true; + if(!this.isSelectionValid(event.node)){ + currentState = false; + } else { + currentState = true; + } } else { currentState = false; } @@ -293,6 +306,23 @@ export class ANDSVocabComponent extends SimpleComponent { return val; } + public isSelectionValid(childNode: any) { + let valid = true; + if(this.field.disableCheckboxRegexEnabled) { + const data = childNode.data; + let nodeId = _.get(data,this.field.disableCheckboxRegexTestValue); + let re = new RegExp(this.field.disableCheckboxRegexPattern,'i'); + if(!_.isUndefined(nodeId)) { + let reTest = re.test(nodeId.toString()); + console.log(nodeId + ' ' + this.field.disableCheckboxRegexTestValue + ' ' + reTest); + if(!reTest) { + valid = false; + } + } + } + return valid; + } + public setParentTree(val:any, childNode: any) { const parentNotation = _.get(childNode, 'parent.data.notation'); if (!_.isUndefined(parentNotation)) {