[6.x] fix choosing random elements on <select> #822
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The browser
select()
method will currently choose a random option from a<select>
input if the second parameter evaluates tonull
. This normally works fine if it is used like:However, it becomes problematic when a second argument is passed that evaluates as
null
.In this scenario, if
$user->status
isnull
, we actually want the<select>
to not be set, but instead it will select a random<option>
.It also makes it more difficult to edit a value from a selected option to a
null
option.This will again select a random
<option>
, when we really want the value to be cleared out.Solution
This PR will switch from checking if the second argument is
null
, to checking if it was even passed.This will select a random option:
while this will specifically try to select an option whose value evaluates to an empty string:
I go back and forth on if this is a breaking change or a bug fix. If we go by the documentation (https://laravel.com/docs/8.x/dusk#using-forms), this is a bug fix. If you guys deem it as a BC, and can resend to master.