Eugene Starosvetskiy
Eugene Starosvetskiy

Reputation: 141

Change input value on change dropdown

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!

Upvotes: 1

Views: 91

Answers (1)

Zakir hussain
Zakir hussain

Reputation: 631

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 ?

Upvotes: 1

Related Questions