0

i'm trying to get the first selection from my list, the dropdown is showing all options, but the first option (the selected) is null.

Below my code


<div class="form-group mb-6">
  <label class="form-label">{{ $trans('labels.department') }}</label>
  <select class="form-select" v-model="form.department_id">
    <option  :value="department.id" v-for="department in $page.departments">
      <p class="mt-1 text-sm leading-5 text-gray-500">
        {{ department.name }}
      </p>
    </option>
  </select>
</div>

3
  • Is your dropdown not showing any items when you click on it? Commented Nov 25, 2021 at 14:44
  • is showing all options, but the first option (the selected) is null Commented Nov 25, 2021 at 14:47
  • Try to display it upon the condition that its value is not null Commented Nov 25, 2021 at 14:52

1 Answer 1

1

try initializing it inside created(). It will select the first option from the loop.

ex.

created() {
  this.form.department_id = this.$page.departments[0].id
}
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.