-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Modal closing when the value changes in component #1389
Copy link
Copy link
Closed
Description
The modal closes automatically when the value of a variable is
Steps to reproduce
Context
- Livewire version: [e.g. 1.0.0]
- Laravel version: [e.g. 7.0.0]
- Browser: [ Chrome]
view:
`
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">New Enquiry</h4>
<button type="button" class="close" data-dismiss="modal" data-target="#myModal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<form action="{{route('enquiries.create')}}" wire:modal.prevent method="post" class=" form text-center">
@csrf
<div class="row">
<div class="col-lg-4 form-group text-left">
<label for="spin">Source Pin</label>
<input type="number" class="form-control" value="452010" name="spin" id="spin" placeholder="000000" wire:model.lazy='spin' wire:change.lazy="$emit('spincodeAdded')">
</div>
<div class="col-lg-4 form-group text-left">
<label for="dpin">Delivery Pin</label>
<input type="number" class="form-control" name="dpin" id="dpin" placeholder="000000" wire:model.lazy='dpin' wire:change.lazy="$emit('dpincodeAdded')">
</div>
<div class="col-lg-4 form-group text-left">
<label for="requirementDate">Requirement Date</label>
<input type="date" class="form-control" value="<?= date('Y-m-d', time()); ?>" min="<?= date('Y-m-d', time()); ?>" name="requirementDate" id="requirementDate">
</div>
<div class="col-lg-6 form-group text-left">
<label for="source">Source City*</label>
<input type="text" class="form-control" name="source" id="source" value="@if($source){{$source['locality']}}@endif" placeholder="City - District - State">
</div>
<div class="col-lg-6 form-group text-left">
<label for="destination">Destination City*</label>
<input type="text" class="form-control" name="destination" id="destination" value="@if($destination){{$destination}}@endif" placeholder="City - District - State">
</div>
component:
`<?php
namespace App\Http\Livewire;
use App\pincode;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
class EnquiryModal extends Component
{
public $spin;
public $dpin;
public $source;
public $destination;
protected $listeners = [
'spincodeAdded',
'dpincodeAdded',
];
public function spincodeAdded()
{
$addressofsource = pincode::where('pincode', $this->spin)->first();
// dd($addressofsource['locality']);
$this->source = $addressofsource;
}
public function dpincodeAdded()
{
$addressofdelivery = DB::select('select locality from pincodes where pincode = ? limit 1', [$this->dpin]);
$addressofdelivery =$addressofdelivery[0]->locality;
$this->destination = $addressofdelivery;
}
public function render()
{
return view('livewire.enquiry-modal');
}
}
`
Tried removing js, preventing default actions, calling the model by js, keeping the modal static, open by deafult but it gets closed as soon as the data loads
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels