Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How do I make the input required? #2

Open
ziming opened this issue Jul 1, 2020 · 4 comments
Open

Question: How do I make the input required? #2

ziming opened this issue Jul 1, 2020 · 4 comments

Comments

@ziming
Copy link

ziming commented Jul 1, 2020

How do I make the input field have html5 required attribute?

Thank you and have a nice day

@asantibanez
Copy link
Owner

Hey @ziming. Thanks for your interest in the library.

You can export the views of the library and add it manually yourself in the default.blade.php view file under the vendor/livewire-select folder.

@ziming
Copy link
Author

ziming commented Jul 5, 2020

Hmm i'm kinda a noobie here so all my livewire select field will now be required? How do I make it on a case by case basis?

Currently i do it this way for search-input.blade.php, but it applies to all livewire select search fields

<input
    id="{{ $name }}"
    type="text"
    placeholder="{{ $placeholder }}"
    class="{{ $styles['searchInput'] }}"
    required
    wire:keydown.enter.prevent=""
    wire:model.debounce.300ms="searchTerm"

    x-on:click="isOpen = true"
    x-on:keydown="isOpen = true"

    x-on:keydown.arrow-up="selectUp(@this)"
    x-on:keydown.arrow-down="selectDown(@this)"
    x-on:keydown.enter.prevent="confirmSelection(@this)"
/>

@teofanis
Copy link

teofanis commented Oct 5, 2020

Hey @ziming,
The way I handle this is by using the afterMount($extras=[]) on my livewireselect component and then in the default.blade.php I check
array_key_exists('required', $extras) ? 'required' : '';
Hope it helps.

@luigi-dv
Copy link

luigi-dv commented Oct 8, 2021

Hi,

Are you using your component as a child one? In this case follow this steps:

-Call the Livewire model in your parent component

Hope this helps you 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants