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

Frontend context to get current form fields #1338

Open
enkelmedia opened this issue Dec 17, 2024 · 4 comments
Open

Frontend context to get current form fields #1338

enkelmedia opened this issue Dec 17, 2024 · 4 comments

Comments

@enkelmedia
Copy link

I'm working on a custom Property Editor UI for forms where I would like to get all the fields for the current form.

I know that the NPM-package is work in progress but I wanted to ask.

  1. Is there any way for me to access the fields from within a property editor ui?
  2. Will this be supported with the upcoming NPM package?
@AndyButland
Copy link

Yes, we had exactly the same need in building an integration for Forms where we wanted to get all the fields from the current form. For now, we did it by creating a management API controller within the package to make available the fields for the form - but that's not ideal clearly, as the data is already in the browser.

So for 1. - that's the workaround for now. And for 2. - yes, that's one of the use cases we want to meet.

@enkelmedia
Copy link
Author

Thanks @AndyButland!

In my scenario, building a property editor ui to be used for a workflow type, the list of fields needs to be "real time" so fetching from the server is indeed not optimal since the form might not have been saved when workflow actions are edited.

I kind of hacked around and found that this information is available on your UmbWorkspaceContext, it's a public API but I'm not sure if you will consider it public and not change in minors?

It looks like this works, I guess it might be fragile, but this solves the need that I currently have:

this.consumeContext('UmbWorkspaceContext', (i)=>{
  var instance = i as FakeFormsWorkspaceContext;

  console.log('Forms UmbWorkspaceContext',instance);

  this.observe(instance.data,(forms)=>{

    console.log('Forms data',forms);

    // This will list form fields
    forms.pages.forEach((page)=>{
      page.fieldSets.forEach((fieldSet)=>{
        fieldSet.containers.forEach((container)=>{
          container.fields.forEach((field)=>{
            console.log('field',field);
          })
        })
      })
    });
  });
});

In the future, it would be nice to know that this (or something similar) is considered public API, and also if the types was exposed via a NPM package, much like I've done with my e-mail package

https://www.npmjs.com/package/@newsletterstudio/umbraco

Cheers!

@AndyButland
Copy link

That's ingenious, but may not be the best way to go about if when we get the npm package ready. I'd expect then you'll be able to use our "form context", which will give you methods like getAllFields so you don't have to parse them yourself.

I've tagged this issue along with the work we have in our internal tracker, so we'll make sure to update here when we have it ready, and illustrate how we are using it in our integrations. // @dtng95 ... FYI.

@enkelmedia
Copy link
Author

Great stuff :) Thanks for keeping me posted.

Cheers!

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