Run code before and after running a generator Pro only

Fake Data allows you to run javascript code before and after a generator is executed. This can be useful if you want to delay the execution for a specific field, or want to do some other actions with on the input field.

In order to set up the two callbacks, follow these steps:

  • Open Fake Data's options page
  • Go to Generators -> Default Generators tab
  • Find the generator you want to update, and click on the manage icon:
  • On the newly opened popup, there are two options that you can enable:
    • Callback before insert: - will allow you to add javascript code that will be executed before the generator is triggered
    • Callback after insert: - will allow you to add javascript code that will be executed after the generator is triggered
  • Once you enable any of the two options (or both), a code editor will show up, and you can type your javascript code

If you want to access the DOM element that is filled by Fake Data, you can refer to arguments[0] in the code.

TIP

Doing the steps described above, will change the setting for all fields that are using the generator you updated. You can also change this setting only for a single field, either through the Fields page, or by clicking on the "Manage Field" option from the context menu.