Skip to content

Commit

Permalink
[Closes #393, Closes #394] Allow tab into Nil? checkbox, show Nil? on…
Browse files Browse the repository at this point in the history
…ly on first of repeating element, clear other values on Nil? selected (#395)
  • Loading branch information
francisli authored May 17, 2024
1 parent 9c2410a commit 208e842
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ export class XsdElementBaseComponent {
this.delValue();
this.setAttr('xsi:nil', 'true');
this.NV = this.nilValues[0]?.['xs:restriction']?.['xs:enumeration']?._attributes?.value;
// if this is a repeating element, remove the other values
if (Array.isArray(this.data[this.name]) && this.data[this.name].length > 1) {
this.data[this.name].splice(1, this.data[this.name].length - 1);
}
} else {
this.delAttr('xsi:nil');
this.delAttr('NV');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h5 *ngIf="isDisplayOnly" [class.text-danger]="isInvalid">
</div>
</div>
<div *ngIf="!isDisplayOnly" class="form-field__content">
<button (click)="onAdd()" class="btn btn--sm btn--secondary" type="button">Add</button>
<button [disabled]="!canAdd" (click)="onAdd()" class="btn btn--sm btn--secondary" type="button">Add</button>
</div>
</ng-container>
<ng-container *ngIf="!isMulti">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ export class XsdElementMultiComponent extends XsdElementBaseComponent {
super(api);
}

get canAdd() {
if (Array.isArray(this.data[this.name])) {
if (this.data[this.name].length > 0) {
return this.data[this.name][0]._attributes?.['xsi:nil'] !== 'true';
}
} else {
return this.data[this.name]?._attributes?.['xsi:nil'] !== 'true';
}
return true;
}

onAdd() {
this.addValue({});
setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
</option>
</select>
</div>
<div *ngIf="isNillable && !isDisplayOnly" class="input-group-append">
<div *ngIf="isNillable && !isDisplayOnly && !index" class="input-group-append">
<div class="form-check">
<input [(ngModel)]="isNil" [id]="formName + '-nil'" tabindex="-1" type="checkbox" class="form-check-input" />
<input [(ngModel)]="isNil" [id]="formName + '-nil'" type="checkbox" class="form-check-input" />
<label [for]="formName + '-nil'" class="form-check-label">Nil?</label>
</div>
</div>
Expand Down

0 comments on commit 208e842

Please sign in to comment.