Ad

Change Input Value On Change Dropdown

- 1 answer

In creating section (New Record) when I select hotel room from dropdown I want to output price of selected room to another input.

Thank you in advance!

Ad

Answer

you will need to use dependsOn field property.

hotel_room:
    label: Hotel Room
    type: dropdown

price:
    label: Price
    type: text
    dependsOn: hotel_room

Now whenever you will select a value from hotel_room dropdown then below method will be called on attached model in which you can set the value of price field.

public function filterFields($fields, $context = null)
{
    if (isset($fields->price)) {

        //Write your logic here to get Hotel Price value by hotel id
        $hotel_price = 25//For example
        $fields->price->value = $hotel_price;
    }
}

Let me know if you need more help ?

Ad
source: stackoverflow.com
Ad