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

Add an event when FormulateForm is intialized/mounted #384

Closed
Rednas83 opened this issue Feb 23, 2021 · 12 comments
Closed

Add an event when FormulateForm is intialized/mounted #384

Rednas83 opened this issue Feb 23, 2021 · 12 comments
Labels
feature request New feature or request
Projects
Milestone

Comments

@Rednas83
Copy link

Rednas83 commented Feb 23, 2021

Currently you can only guess when the form is initialized.

I think there are 2 possible solutions for this

Solution 1: Trigger the input event after the form is fully loaded

  <FormulateForm
    v-model="data"
    :schema="items"
    @input="update($event)" // Emitted on change (only after mounted event and when the form is fully initialized!) 
/>

Solution 2: Add an additional event

  <FormulateForm
    v-model="data"
    :schema="items"
    @input="update($event)" //  Emitted on change (only after mounted!)
    @mounted="update($event)" //  Emitted when the form is fully initialized/mounted
  />

Actual behaviour

  <FormulateForm
    v-model="data"
    :schema="items"
    @input="update($event)" // Emitted on change (also during mount/initialization! Why is this necessary?)
   />
@Rednas83 Rednas83 added the feature request New feature or request label Feb 23, 2021
@justin-schroeder justin-schroeder added this to 2.x.x in Roadmap Mar 1, 2021
@justin-schroeder justin-schroeder modified the milestones: 2.5.1, 2.5.0 Mar 1, 2021
@justin-schroeder
Copy link
Member

A created event has been added in release/2.5.1.

@Rednas83
Copy link
Author

Rednas83 commented Mar 2, 2021

Doesn't seems to work anymore
https://codepen.io/rednas83/pen/ZEBomOM

I am also not able to find it in the docs anywhere.

@justin-schroeder
Copy link
Member

release/2.5.1 is a branch, it hasn't been published yet.

@Rednas83
Copy link
Author

Rednas83 commented Mar 6, 2021

Great! Will you also block the input event during creation (so that only the user is able to change inputs)?

@justin-schroeder
Copy link
Member

Unfortunately I don’t understand what you’re asking for @Rednas83. Can you give me an example of what/how this is useful?

@Rednas83
Copy link
Author

Rednas83 commented Mar 6, 2021

The use is
*More speed on loading the form ( input event is only triggered after creation, preventings scripts to run unnecessarily)
*Simpler debugging (because there are much less events on the bus => 1 after creation and 1 for each input event)
*Perhaps no need anymore for the created event?

I think it also makes more sense because the input event is intended for input changes from the user.

Expected behaviour

  <FormulateForm
    v-model="data"
    :schema="items"
    @created="update($event)" // Emitted when the form is fully initialized/mounted
    @input="update($event)" // Emitted on change (only after mounted event and when the form is fully initialized!) 
/>

Actual behaviour

  <FormulateForm
    v-model="data"
    :schema="items"
    @input="update($event)" // Emitted on change (also during mount/initialization! Why is this necessary?)
   />

@Rednas83
Copy link
Author

Rednas83 commented Mar 17, 2021

Just noticed an issue with the new created event. It's also triggered when items is undefined or asynchronous (ie: promise).

@justin-schroeder
Copy link
Member

@Rednas83 the created event really has nothing to do with the schema. it's based on the form. If you dont provide anything for the form to render, the form still get's created. Perhaps in your created handler you could check if items is falsey.

@Rednas83
Copy link
Author

...But if you provide an asynchronous schema it will also trigger the created event before the form is actually rendered. I think the created event should be blocked as long items is still a promise.

You can do this by checking if Array.isArray(items) or by !items.then (promises have a then method).

@justin-schroeder
Copy link
Member

justin-schroeder commented Mar 17, 2021

Sure, but that request is specific only if the form is using a schema. The created event is not specific to your particular implementation. The created event is accurately triggered when the FormulateForm is created. If you have other async things going on in user land, those are not really in the scope of the project. if you want to only trigger the @created event when your schema mounts, why not just put a v-if on the FormulateForm for something like v-if="items.length".

@Rednas83
Copy link
Author

I don't understand. Why would you emit the created event if there is no form (schema=undefined) or if the schema is still pending (schema=promise)?

This is now my actual behaviour
image

The created event is emitted before the form is actually created.

@justin-schroeder
Copy link
Member

the form is literally the <form> object. that mounts immediately. I think maybe you're expecting the created event to act like a "schema-mounted" event which currently does not exist. Feel free to submit a feature request or PR for that instead.

This created event, as far as i can tell, is working as intended. It fires when the form is created (and for most cases that is the same fields mounting).

@wearebraid wearebraid locked as resolved and limited conversation to collaborators Mar 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature request New feature or request
Projects
Roadmap
2.x.x
Development

No branches or pull requests

2 participants