Closed XavierColombel closed 6 years ago
Hi @XavierColombel, thanks for the feedback.
This is a documentation issue in the Mongoose section. The following code:
Liana.collection('customers', {
actions: [{
name: 'Send money',
fields: [{
field: 'amount',
isRequired: true,
description: 'Amount',
type: 'Number'
}],
values: (context) => {
return {
amount: 123
};
}
}]
});
should work as expected. The logic to pre-fill values is per action form, that's why it is defined in an action object.
We'll do the documentation fix next week.
🌲🌲🌲
Thanks @arnaudbesnier but it's not working. Maybe you should try by yourself before you fix the documentation. It might be a bug elsewhere.
Maybe you should follow this documentation example: https://doc.forestadmin.com/developer-guide/lumber.html#prefill-a-form-with-default-values
This feature is available on Single
action type only. You need to specify this in your action too I guess.
Do you use the latest liana version?
I use the last version of Liana "forest-express-mongoose": "^2.14.5"
and when I put type="single"
, in an action, it simply removes all custom actions from the list.
Liana.collection("customers", {
actions: [
{
name: "Send money",
type: "single",
fields: [
{
field: "amount",
isRequired: true,
description: "Amount",
type: "Number",
},
],
values: context => {
console.log(context);
return {
amount: 123,
};
},
},
],
});
@XavierColombel, this is what I just tried:
Liana.collection('invoice', {
actions: [{
name: 'Charge',
type: 'single',
fields: [{
field: 'foo',
type: 'String',
}, {
field: 'value',
type: 'Number',
}],
values() {
return {
foo: 'bar',
value: 42,
};
},
}],
});
and it worked as expected:
It should be another problem. It's definitely not working on my side. Here is a video of my files and how it works, if you wanna have a look : https://streamable.com/0sgsc
Hi @XavierColombel,
"Single" actions are actions only available from a record detail view. So, it is normal that, in your screencast, when you set the action as "Single" it disappears from the collection list actions. You have to click on a record to be able to the see the action. (See https://doc.forestadmin.com/developer-guide/lumber.html#configuring-the-accessibility-of-a-smart-action for more details).
Second point, the form pre-fill feature is only available only on "Single" type actions.
Let me know if your issue persists.
@arnaudbesnier thank you for this explanation, it's clear for me now. I hope you could add this feature to list view, soon. 👍
@arnaudbesnier, it's not working with Enums, right?
Any plans to support settings default values on a bulk action?
The documentation does not mention this only works on single actions, took me quite some time to figure out it doesn't work on bulk. @arnaudbesnier – maybe update the docs to mention this?
Hi @robertvanhoesel,
Do the default values you want to set in the Smart Action form depend on the selected records?
If those values are always the same, you should be able to use the defaultValue
option on the declared Smart Action fields.
The documentation mentions that the values
function can be implemented for "single" actions only:
https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions#prefill-a-form-with-default-values
Hi @arnaudbesnier,
It's the same default value for all records. I was not aware of the defaultValue option, that definitely does the trick. Thanks!
In Actions, I'm trying to prefill a form with dynamic default values. So I used the example here and it's like
value
function has no effect on fields. No field is prefilled.I'm running on Express server.