Skip to content

fix #274 Button close does not exist in the NoFramework Component. fix for set error: Invalid JSON on returnEmptyFields: true #282 #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,62 @@
import { Component, Input } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import * as _ from 'lodash';
import { JsonSchemaFormService } from '../../json-schema-form.service';

@Component({
selector: 'no-framework',
template: `
<button style='float:right;clear: right;' *ngIf="showRemoveButton"
type="button"
(click)="removeItem()">
<span aria-hidden="true">&times;</span>
</button>
<select-widget-widget
[dataIndex]="dataIndex"
[layoutIndex]="layoutIndex"
[layoutNode]="layoutNode"></select-widget-widget>`,
[layoutNode]="layoutNode"></select-widget-widget>
`,
})
export class NoFrameworkComponent {
export class NoFrameworkComponent implements OnInit {

options: any; // Options used in this framework
parentArray: any = null;
isOrderable = false;

@Input() layoutNode: any;
@Input() layoutIndex: number[];
@Input() dataIndex: number[];

constructor(
public jsf: JsonSchemaFormService
) { }

ngOnInit() {
this.options = _.cloneDeep(this.layoutNode.options);
if (this.layoutNode.arrayItem && this.layoutNode.type !== '$ref') {
this.parentArray = this.jsf.getParentNode(this);
if (this.parentArray) {
this.isOrderable = this.layoutNode.arrayItemType === 'list' &&
!this.options.readonly && this.parentArray.options.orderable;
}
}
}


get showRemoveButton(): boolean {
if (!this.options.removable || this.options.readonly ||
this.layoutNode.type === '$ref'
) { return false; }
if (this.layoutNode.recursiveReference) { return true; }
if (!this.layoutNode.arrayItem || !this.parentArray) { return false; }
// If array length <= minItems, don't allow removing any items
return this.parentArray.items.length - 1 <= this.parentArray.options.minItems ? false :
// For removable list items, allow removing any item
this.layoutNode.arrayItemType === 'list' ? true :
// For removable tuple items, only allow removing last item in list
this.layoutIndex[this.layoutIndex.length - 1] === this.parentArray.items.length - 2;
}

removeItem() {
this.jsf.removeItem(this);
}
}
3 changes: 3 additions & 0 deletions src/lib/src/shared/jsonpointer.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,10 @@ export class JsonPointer {
console.error(`forEachDeep error: Iterator is not a function:`, fn);
return;
}
const firstPointerPart = pointer.split('/')[1];
if (firstPointerPart && rootObject.hasOwnProperty(firstPointerPart)) {
if (!bottomUp) { fn(object, pointer, rootObject); }
}
if (isObject(object) || isArray(object)) {
for (let key of Object.keys(object)) {
const newPointer = pointer + '/' + this.escape(key);
Expand Down