1

I have these array of input text :

<input type="text" name="amount[0]">
<input type="text" name="amount[1]">
<input type="text" name="amount[2]">
<input type="text" name="amount[3]">

and I want to type a value using Laravel Dusk. I can't just hardcode using :

$browser->visit('/create')
    ->type('amount[0]', '100')
    ->type('amount[1]', '100')
    ->type('amount[2]', '100')
    ->type('amount[3]', '100');

because the number of input fields depends on the number of items in the database.

I tried using :

$browser->visit('/create')
    ->type('amount[]', '100');

but it doesn't work. Is there a way to achieve this?

1 Answer 1

4

You can find the inputs with a CSS selector:

$inputs = $browser->elements('input[name^="amount["]');

foreach ($inputs as $input) {
    $input->sendKeys('100');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.