Skip to content
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

Cannot render formProperty.Properties to initial data for array widget #318

Open
tqduy opened this issue Jan 31, 2020 · 1 comment
Open

Comments

@tqduy
Copy link

tqduy commented Jan 31, 2020

Hi everyone,
I have a case which I cannot binding the existing schema data to array widget.
In component A, I have:
<sf-form *ngIf="showSchema" [schema]="schema" [validators]="fieldValidators" [actions]="actions" [(model)]="schemaData "> </sf-form>
where I render the initSchemaValue as the init data for the sf-form and I create an array-widget.component.ts:
export class IonicArrayWidgetComponent extends ArrayWidget implements AfterViewInit
with html :

        <div *ngFor="let itemProperty of formProperty.properties; let i=index" class="assessment">
            <sf-form-element [attr.id]="i" [formProperty]="itemProperty"></sf-form-element>
            <ion-row class="button-group" class="ion-justify-content-around">
                <ion-col col-5>
                    <ion-button icon-start color="danger" expand="block" fill="outline" item-right
                        (click)="removeItem(itemProperty, i)">
                        <ion-icon name="close"></ion-icon>&nbsp;Remove
                    </ion-button>
                </ion-col>
                <ion-col col-5>
                    <ion-button expand="block" fill="outline" icon-start color="secondary" item-right
                        (click)="addItem()">
                        <ion-icon name="add"></ion-icon>&nbsp;Add
                    </ion-button>
                </ion-col>
            </ion-row>
        </div>

Here is the schema and data:
image

this.schemaData = [{
		"component": "a",
		"part": "a",
		"fault": "a",
		"location": "a",
		"comment": "a",
		"status": "a",
		"calculatedComment": "a",
		"calculatedNZTACode": "a"
	},
	{
		"component": "b",
		"part": "b",
		"fault": "b",
		"location": "b",
		"comment": "b2",
		"status": "b",
		"calculatedComment": "b"
	}
];

The layout will look like this:
image

The problem is that I cannot bind the data to the schema template as initial data. In the array-widget, I see that the formProperty.properties is not received the schemaData:
image
which it should be look like this:
image

Can anyone help me with this cases,
Thank you!

@aderman
Copy link

aderman commented Apr 9, 2021

It happens because when initialising form.component in ngOnChanges method below line is executed

this.rootProperty = this.formPropertyFactory.createProperty(this.schema);

createProperty eventually calls initializeRoot which effectively resets the array values. again in form.component there is this line which is commented out

 if (this.model) {
        // this.rootProperty.reset(this.model, false);
   }

I'll update this thread If I can fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants