Get data from another table (suppliers) after selecting a supplier #364
-
Hi, In my ArticleCrudController -> after selecting a supplier from the table suppliers, I want to get data from other columns from the table supplier, like fee, transport en marge so I can calculate, inside the panel Article, automatically the selling price from the given purchase price. What is the best way to achieve this? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @ceeckhout A good approach for it would be to create you custom field, let's call it It could start as a copy of the relationship select, but then you add a bit of javascript, that when the supplier is selected, it will send an ajax request to some endpoint you created with the selected supplier, you will do the needed calculations and return the results. Again, use javascript to display/update them when supplier changes. That way you will keep the default relationship select from backpack untouched and able to be reused in other cruds where you don't need that functionality. Also you could then use this custom field in other cruds that need it. Hope it helps, 🙏 |
Beta Was this translation helpful? Give feedback.
Hello @ceeckhout
A good approach for it would be to create you custom field, let's call it
vendor/backpack/crud/fields/select_with_shipping_costs.blade.php
.It could start as a copy of the relationship select, but then you add a bit of javascript, that when the supplier is selected, it will send an ajax request to some endpoint you created with the selected supplier, you will do the needed calculations and return the results. Again, use javascript to display/update them when supplier changes.
That way you will keep the default relationship select from backpack untouched and able to be reused in other cruds where you don't need that functionality. Also you could then use this custom field …