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

Uncaught TypeError: Cannot read property 'firstChild' of undefined #351

Open
santigolucass opened this issue Oct 11, 2024 · 1 comment
Open

Comments

@santigolucass
Copy link

I'm having this error while trying to render the form. I'm building it using Rails + Stimulus.

My setup:

<div data-controller="formeo" style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
  <div data-formeo-target="renderer"></div>
  <div data-formeo-target="editor" style="min-height: 500px; border: 1px solid #ccc;"></div>
  <button data-action="formeo#renderForm">Render Form</button>
</div>
// app/javascript/controllers/formeo_controller.js
import { Controller } from '@hotwired/stimulus';
import { FormeoEditor, FormeoRenderer } from 'formeo';

export default class extends Controller {
  static targets = ['editor', 'renderer'];

  connect() {
    const editorContainer = this.editorTarget;

    if (!editorContainer) {
      console.error('Editor container not found!');
      return;
    }

    const options = {
      editorContainer: editorContainer,
      events: {
        onSave: this.saveFormData.bind(this),
      }
    };

    this.editor = new FormeoEditor(options);
  }

  saveFormData() {
    const formData = this.editor.formData;

    console.log('Form data:', formData);
  }

  renderForm() {
    const formData = this.editor.formData;
    const rendererContainer = this.rendererTarget;

    if (!rendererContainer) {
      console.error('Renderer container not found!');
      return;
    }


    const options = {
      rendererContainer,
    };

    console.log('Rendering options:', options);
    console.log('Rendering form:', formData);
    const renderer = new FormeoRenderer(options)
    renderer.render(formData)
  }

}

Screenshot 2024-10-11 202112

@santigolucass santigolucass changed the title https://github.com/Draggable/formeo/issues/303 Uncaught TypeError: Cannot read property 'firstChild' of undefined Oct 12, 2024
@kevinchappell
Copy link
Collaborator

i tried looking into this but i am not able to replciate. stimulus does not seem to work well outside of rails and webpack. If you can fork this sandbox and get stimulus to work i can look into this further:
https://codesandbox.io/p/sandbox/jpf74p

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