Skip to content

Commit

Permalink
Add configurable regex validation to exclude selected checkboxes in a…
Browse files Browse the repository at this point in the history
…ndsvocab component (#1155)
  • Loading branch information
alejandro-bulgaris-qcif authored Dec 15, 2022
1 parent 0cc3ee1 commit 35c06d2
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions angular/shared/form/field-andsvocab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ export class ANDSVocabField extends FieldBase<any> {

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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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":
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 35c06d2

Please sign in to comment.