groceryCrudSetFieldValue

Hello everyone, how do I use this command in the view?
I need to dinamically change an input value. I found this command in the forum but if I use for example

groceryCrudSetFieldValue(‘nameField’, ‘valueField’)

it return undefined. I use it into the view. I have GC 3.0.11.
Thanks

Hello @Mattia ,

Please make sure that you use the groceryCrudSetFieldValue only after the add or edit form is opened. Keep in mind that this function is setting live in JavaScript the field. So for example you can do something like this:

window.addEventListener('gcrud.form.edit-load', ({detail}) => {
    // use groceryCrudSetFieldValue(‘nameField’, ‘valueField’) here
});

or:

window.addEventListener('gcrud.form.add-load', () => {
        // use groceryCrudSetFieldValue(‘nameField’, ‘valueField’) here
});

Also make sure that the “publish_events” configuration is true at your configuration. The default value is false

Let me know if that worked for you.

Regards
Johnny

Thank you, now it works!

1 Like