<jet-button class="bg-green-600 m-auto"
#click="creatingProductCategory = true"
>Create New</jet-button>
<jet-dialog-modal :show="creatingProductCategory" #close="creatingProductCategory = false">
<template #title>Create New Product</template>
<template #content>
<form #submit.prevent="submit">
<div>
<jet-label for="email" value="Product Category"/>
<select name="" id=""
class="block w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
>
<option value="1">Macrame</option>
<option value="2">Coords</option>
<option value="3">Plant</option>
<option value="4">Accessories</option>
</select>
</div>
<div class="mt-4">
<jet-label for="email" value="Product Name"/>
<jet-input id="email" type="email" class="mt-1 block w-full" v-model="form.email"
placeholder="Enter Product Name"
required autofocus/>
</div>
<div class="mt-4">
<jet-label for="password" value="Price"/>
<jet-input id="password" type="password" class="mt-1 block w-full"
placeholder="Enter Price"
v-model="form.password" required autocomplete="current-password"/>
</div>
<div class="flex items-center justify-end mt-4">
<jet-button class="ml-4" :class="{ 'opacity-25': form.processing }"
:disabled="form.processing">
Create
</jet-button>
</div>
</form>
</template>
</jet-dialog-modal>
This is the button component i have used that comes within jetstream templates.
But when i click the button the value of the variable 'creatingProductCategory' doesnt change.
Iam missing something important here !
Also if you have links to some good documentation it would be of great help :)
As Rwd mentiond in comment you need to add .native to #click:
<jet-button type="button" #click.native="someFunction" class="mr-4">
press button
</jet-button>
I got a simple way around it.
<button class="bg-green-600 m-auto inline-flex items-center px-4 py-2 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:shadow-outline-gray transition ease-in-out duration-150"
#click="creatingProductCategory = true"
>Create New</button>
I used generic html5 buttons and gave it the class that was being used in jetstream buttons . It loooks exactly the same and the click handler works now
Related
I have a form with several input fields and some of them render conditionally using AlpineJS x-if, those elements have wire:model data, but when the elements rendered conditionally the model binding seems not working. I tried to print the variable on the element but it doesn't work. Without x-if it works fine.
<div class="form-check" >
<input class="form-check-input appearance-none rounded-full h-4 w-4 border border-gray-300 bg-white checked:bg-[#60D619] checked:border-[#60D619] focus:outline-none transition duration-200 mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2 cursor-pointer" type="radio" id="company" wire:model="isCompany" #click="open = true" value="true">
<label class="form-check-label inline-block px-1 text-sm text-gray-600" for="company">
Yes, I'm a company.
</label>
</div>
<div class="form-check">
<input class="form-check-input appearance-none rounded-full h-4 w-4 border border-gray-300 bg-white checked:bg-[#60D619] checked:border-[#60D619] focus:outline-none transition duration-200 mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2 cursor-pointer" type="radio" id="person" wire:model="isCompany" #click="open = false" value="false">
<label class="form-check-label inline-block px-1 text-sm text-gray-600" for="person">
No. I'm not a company.
</label>
</div>
<div class="py-1" x-show="open" x-transition>
<span class="px-1 text-sm text-gray-600">Company Name</span>
<input wire:model.lazy="companyName" placeholder="" type="text"
class="text-md block px-3 py-2 rounded-lg w-full
bg-white border-2 border-gray-300 placeholder-gray-600 shadow-md focus:placeholder-gray-500 focus:bg-white focus:border-gray-600 focus:outline-none">
</div>
<div class="py-1" x-show="!open" x-transition>
<span class="px-1 text-sm text-gray-600">User Name</span>
<input wire:model="name" placeholder="" type="text"
class="text-md block px-3 py-2 rounded-lg w-full
bg-white border-2 border-gray-300 placeholder-gray-600 shadow-md focus:placeholder-gray-500 focus:bg-white focus:border-gray-600 focus:outline-none">
</div>
<div class="py-1" x-show="!open" x-transition>
<span class="px-1 text-sm text-gray-600">First Name</span>
<input wire:model="fullName" placeholder="" type="text"
class="text-md block px-3 py-2 rounded-lg w-full
bg-white border-2 border-gray-300 placeholder-gray-600 shadow-md focus:placeholder-gray-500 focus:bg-white focus:border-gray-600 focus:outline-none">
</div>
When x-show uses the issue goes away but the unnecessary input fields are not cleared. I don't want those data to be saved on the database. Is this because x-show only toggles the visibility of the elements and x-if completely removes the element from the DOM? Or is there a way to reset the values of the input fields when visibility is toggled using x-show?
x-if indeed removes the element, while x-show only hides it.
wire:model only works if it's loaded in with Livewire. Else Livewire doesn't "know" those fields exist, and thus can't add an event listener to detect change/input/etc. Therefore, you want to do what #Bennett already mentioned, and only hide the inputs, and clear the fields.
You can use $wire to directly clear the input. Otherwise, you will have to dispatch a change or input event on the input field (change for lazy, input for non-lazy).
I have a form that contains an email input and a submit button. On Iphone, when I type something on email and delete it, button slide down a little bit. I use tailwind css and what causes this problem?
<form wire:submit.prevent="submit">
<span class="inline-grid">
<input type="text" name="email" wire:model.defer="email" class="form-control relative flex-auto desktop:rounded-lg below-desktop:rounded placeholder-gray-300 desktop:h-14 below-desktop:h-8 xl:w-72 small-desktop:w-60" placeholder="{{__('E-mail')}}" aria-label="Search" aria-describedby="button-addon2" style="border-radius: 4px;">
</span>
<button type="submit" class="bg-blue-400 text-base desktop:rounded-lg below-desktop:rounded text-white desktop:h-14 below-desktop:h-8 px-6 desktop:ml-2 xl:w-32 small-desktop:w-24" style="border-radius: 4px;">{{ __('Send') }}</button>
</form>
Is it possible to actually override a TailwindCSS class with #error from Laravel Validation?
My inputs all have border-none, but I want to apply a border (that is red) only when we throw a validation error.
<form action="/contact" method="POST" class="flex flex-col space-y-8">
{{ csrf_field() }}
<div class="flex flex-col space-y-8 md:flex-row md:space-y-0 md:space-x-5">
<div class="relative">
<label for="text" class="absolute -top-6 left-3 text-sm after:content-['*'] after:ml-0.5 after:text-red-500">Full Name</label>
<input type="text" class="form-input rounded-lg bg-blue-200 border-none shadow #error('full_name') border border-red-500 #enderror" name="full_name" placeholder="John Doe" value="{{ old('full_name') }}" required />
#error('full_name')
<div class="text-sm font-thin text-red-500">{{ $message }}</div>
#enderror
</div>
<div class="relative">
<label for="email" class="absolute -top-6 left-3 text-sm after:content-['*'] after:ml-0.5 after:text-red-500">E-mail</label>
<input type="email" class="form-input rounded-lg bg-blue-200 border-none shadow #error('email') border border-red-500 #enderror" name="email" placeholder="email#example.com" value="{{ old('email') }}" required />
#error('email')
<div class="text-sm font-thin text-red-500">{{ $message }}</div>
#enderror
</div>
</div>
<div class="relative">
<label for="text" class="absolute -top-6 left-3 text-sm">Phone Number</label>
<input type="text" class="form-input rounded-lg w-full bg-blue-200 border-none shadow #error('phone_number') border border-red-500 #enderror" name="phone_number" placeholder="(123) 456-7890" value="{{ old('phone_number') }}" />
#error('phone_number')
<div class="text-sm font-thin text-red-500">{{ $message }}</div>
#enderror
</div>
<div class="relative">
<label for="textarea" class="absolute -top-6 left-3 text-sm after:content-['*'] after:ml-0.5 after:text-red-500">Message</label>
<textarea type="textarea" class="form-textarea rounded-lg w-full bg-blue-200 border-none shadow #error('message') border border-red-500 #enderror" name="message" rows="6" placeholder="Message" value="{{ old('message') }}" required></textarea>
#error('message')
<div class="text-sm font-thin text-red-500">{{ $message }}</div>
#enderror
</div>
<button type="submit" class="rounded-lg w-full md:w-1/2 self-end bg-neutral-900 uppercase font-black text-blue-400 border-none p-2">Send</button>
</form>
Since #error is after border-none, I'd think it would override it...
Use the following option to specify a new input field class
<input type="text" class="form-input rounded-lg w-full bg-blue-200 #if($errors->has('phone_number')) border border-red-500 #else border-none shadow #endif" name="phone_number" placeholder="(123) 456-7890" value="{{ old('phone_number') }}" />
I have a problem with changing my variable based on a selected value.
<div x-data="{material_enabled : false}">
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<div class="mt-1 sm:mt-0 sm:col-span-2">
<select #change="$event.target.value = 'Material fehlt' ? material_enabled=true : material_enabled=false" id="category" name="category" autocomplete="category" class="max-w-lg block focus:ring-indigo-500 focus:border-indigo-500 w-full shadow-sm sm:max-w-xs sm:text-sm border-gray-300 rounded-md">
<option value="" selected>Wähle einen Stillstandsgrund</option>
<option >ungeplanter Stillstand (Maschinenstillstand)</option>
<option >geplanter Stillstand (Instandhaltung geplant)</option>
<option >Rüsten</option>
<option >Wartung durch Mitarbeiter</option>
<option >Material fehlt</option>
</select>
</div>
</div>
<div x-show="material_enabled" class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<label for="order_number" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
Auftragsnummer
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<input type="text" name="order_number" id="order_number" autocomplete="" class="max-w-lg block w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:max-w-xs sm:text-sm border-gray-300 rounded-md"
value="{{ old('order_number', '') }}" />
#error('order_number')
<p class="text-sm text-red-600">{{ $message }}</p>
#enderror
</div>
</div>
</div>
I want to change the material_enabled variable fomr the x-data block to true if the selected value is 'Material fehlt', but this does not work.
Thanks, Armin
Your check for Material fehlt is not right. Use
#change="$event.target.value == 'Material fehlt'
not
#change="$event.target.value = 'Material fehlt'
You compare values with == and assign those with =. So what you did was not a comparison.
Here is a complete example I used:
<html>
<head>
<script
src="https://cdn.jsdelivr.net/gh/alpinejs/alpine#v2.8.0/dist/alpine.min.js"
defer
></script>
<link
href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css"
rel="stylesheet"
/>
</head>
<body>
<div x-data="{material_enabled : false}">
<div
class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5"
>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<select
#change="$event.target.value == 'Material fehlt' ? material_enabled=true : material_enabled=false"
id="category"
name="category"
autocomplete="category"
class="max-w-lg block focus:ring-indigo-500 focus:border-indigo-500 w-full shadow-sm sm:max-w-xs sm:text-sm border-gray-300 rounded-md"
>
<option value="" selected>Wähle einen Stillstandsgrund</option>
<option>ungeplanter Stillstand (Maschinenstillstand)</option>
<option>geplanter Stillstand (Instandhaltung geplant)</option>
<option>Rüsten</option>
<option>Wartung durch Mitarbeiter</option>
<option>Material fehlt</option>
</select>
</div>
</div>
<div class="mt-4">
Value of <strong>material_enabled</strong>:
<span x-text="material_enabled"></span>
</div>
</div>
</body>
</html>
I am using accordion something like this
https://www.tailwindtoolbox.com/components/accordion and I have a input field inside my accordion
<div class="tab-content overflow-y-scroll border-l-2 bg-gray-100 border-indigo-500 leading-normal">
<div class="border border-black mt-3 p-3 grid grid-cols-4">
<div class="col-span-1">
<label for="about" class="block text-sm leading-5 font-medium text-gray-700">
Title
</label>
<div class="rounded-md shadow-sm">
<textarea wire:model="additional_docs.title" name="additional_docs" id="edit_additional_docs" name="" rows="3" class="form-textarea mt-1 block w-full transition duration-150 ease-in-out sm:text-sm sm:leading-5" placeholder="description"></textarea>
</div>
<p class="mt-2 text-sm text-gray-500">
Document Title
</p>
</div>
</div>
The accordion is working fine but as soon as I start typing the accordion closes and I need to open accordion again and start typing, but if I remove wire:model ,it works fine .I am new to live wire and if I use wire:ignore it doesn't help too.
Thanks for any help :)
Add wire:ignore.self on the element which will be hidden/shown.