Skip to content

Commit

Permalink
More bug fixes with embedding feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Nov 23, 2023
1 parent 892e416 commit e1c2bf4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/e
const textField = form.getComponent('textField');
console.log(textField.errors[0].message); // 5.x way of getting the error message for the first error.
```
- EditGrid **validateRows** method now returns an array of errors instead of a boolean "true" or "false". If you wish to do the same thing as before 5.x, then you can use the following code.

```js
const isValid = form.getComponent('editgrid').validateRow().length === 0;
```

- In the 5.x renderer, the errors array will always be populated if there are errors in the form. They may not be displayed depending on the "pristine" state of the rendered form, but the error is always populated if there are form errors. This is different in 4.x where the error property would only contain and error if an error is VISIBLE on the form. This means that it is difficult to determine if a form has errors without executing the checkValidity() method with the dirty flag set to "true". You no longer need to do this in the 5.x renderer.

**4.x Renderer**
Expand Down
36 changes: 33 additions & 3 deletions src/Embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ export class Formio {
}]
}]));

const renderer = Formio.config.debug ? 'formio.form' : 'formio.form.min';
const formioSrc = Formio.config.full ? 'formio.full' : 'formio.form';
const renderer = Formio.config.debug ? formioSrc : `${formioSrc}.min`;
Formio.FormioClass = await Formio.addScript(
wrapper,
Formio.formioScript(Formio.config.script || `${Formio.cdn.js}/${renderer}.js`, builder),
Expand Down Expand Up @@ -342,7 +343,10 @@ export class Formio {

// Called after an instance has been created.
static async afterCreate(instance, wrapper, readyEvent) {
wrapper.removeChild(wrapper.querySelector('.formio-loader'));
const loader = wrapper.querySelector('.formio-loader');
if (loader) {
wrapper.removeChild(loader);
}
Formio.FormioClass.events.emit(readyEvent, instance);
if (Formio.config.after) {
Formio.debug('Calling ready callback');
Expand All @@ -353,6 +357,12 @@ export class Formio {

// Create a new form.
static async createForm(element, form, options = {}) {
if (Formio.FormioClass) {
return Formio.FormioClass.createForm(element, form, {
...options,
...{ noLoader: true }
});
}
const wrapper = await Formio.init(element, options);
return Formio.FormioClass.createForm(element, form, {
...options,
Expand All @@ -372,6 +382,9 @@ export class Formio {

// Create a form builder.
static async builder(element, form, options = {}) {
if (Formio.FormioClass?.builder) {
return Formio.FormioClass.builder(element, form, options);
}
const wrapper = await Formio.init(element, options, true);
return Formio.FormioClass.builder(element, form, options).then((instance) => {
Formio.afterCreate(instance, wrapper, 'builderEmbedded');
Expand All @@ -382,6 +395,9 @@ export class Formio {
// Create a report.
static Report = {
create: async(element, submission, options = {}) => {
if (Formio.FormioClass?.Report) {
return Formio.FormioClass.Report.create(element, submission, options);
}
const wrapper = await Formio.init(element, options, true);
return Formio.FormioClass.Report.create(element, submission, options).then((instance) => {
Formio.afterCreate(instance, wrapper, 'reportEmbedded');
Expand All @@ -407,6 +423,9 @@ export class Form {
}

init() {
if (this.instance && !this.instance.proxy) {
this.instance.destroy();
}
this.element.innerHTML = '';
this.ready = this.create().then((instance) => {
this.instance = instance;
Expand All @@ -419,12 +438,23 @@ export class Form {
return Formio.createForm(this.element, this.form, this.options);
}

setForm(form) {
this.form = form;
if (this.instance) {
this.instance.setForm(form);
}
}

setDisplay(display) {
if (this.instance.proxy) {
return this.ready;
}
this.form.display = display;
this.init();
this.instance.destroy();
this.ready = this.create().then((instance) => {
this.instance = instance;
this.setForm(this.form);
});
return this.ready;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/WizardBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class WizardBuilder extends WebformBuilder {
return (pages && (pages.length >= this.page)) ? pages[this.page] : null;
}

set form(value) {
setForm(value) {
this._form = value;
if (!this._form.components || !Array.isArray(this._form.components)) {
this._form.components = [];
Expand All @@ -124,6 +124,10 @@ export default class WizardBuilder extends WebformBuilder {
this.rebuild();
}

set form(value) {
this.setForm(value);
}

get form() {
return this._form;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ export default class Component extends Element {
if (this.options.onChange) {
this.options.onChange(...args);
}
else if (this.root) {
else if (this.root && this.root.triggerChange) {
this.root.triggerChange(...args);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/_classes/nestedarray/NestedArrayComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export default class NestedArrayComponent extends NestedDataComponent {
return this.validateComponents([this.component], data, flags);
}

checkRow(...args) {
console.log('Deprecation Warning: checkRow method has been replaced with processRow');
return this.processRow.call(this, ...args);
}

processRow(method, data, opts, row, components, silentCheck) {
if (opts?.isolateRow) {
silentCheck = true;
Expand Down
3 changes: 1 addition & 2 deletions src/components/editgrid/EditGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
fastCloneDeep,
Evaluator,
getArrayFromComponentPath,
eachComponent,
getComponentsSchema
eachComponent
} from '../../utils/utils';

const EditRowState = {
Expand Down

0 comments on commit e1c2bf4

Please sign in to comment.