英文:
How can populate data in livewire component of this package "victorybiz/laravel-tel-input"
问题
I am using this package to show phone input with tel, in my livewire php class I am setting data that I want to populate in the component this package provides
我正在使用这个包来展示电话输入,我在我的Livewire PHP类中设置了数据,我想在这个包提供的组件中填充这些数据。
public function mount()
{
$this->data['country_code'] = str_replace("+", "", optional(user())->country_code);
$this->data['phone_no'] = str_replace($this->data['country_code'], '', optional(user())->phone_no);
$this->data['full_no'] = optional(user())->phone_no;
}
Here is my blade file and i have added a livewire component which they have suggested in the docs
这是我的Blade文件,我已经添加了一个Livewire组件,这是文档中建议的方式:
<x-tel-input
wire:model="phone"
id="phone"
name="phone"
class="form-input"
/>
<input wire:model="phone_country" type="hidden" id="phone_country" name="phone_country">
Here is the documentation link Laravel Telephone Input
这是文档链接 Laravel Telephone Input
英文:
I am using this package to show phone input with tel, in my livewire php class I am setting data that I want to populate in the component this package provides
public function mount()
{
$this->data['country_code'] = str_replace("+","",optional(user())->country_code);
$this->data['phone_no'] = str_replace($this->data['country_code'],'',optional(user())->phone_no);
$this->data['full_no'] = optional(user())->phone_no;
}
Here is my blade file and i have added a livewire component which they have suggested in the docs
<x-tel-input
wire:model="phone"
id="phone"
name="phone"
class="form-input"
/>
<input wire:model="phone_country" type="hidden" id="phone_country" name="phone_country">
Here is the documentation link Laravel Telephone Input
答案1
得分: 0
以下是您要翻译的内容:
在 blade 文件中,通过以下方式我已经实现了我想要做的事情:
<x-tel-input
wire:model="users.phone_no"
id="phone_no"
name="phone_no"
class="form-input numeric form-control form-control-lg"
/>
<input wire:model="users.country_code" type="hidden" id="country_code" name="country_code">
在 PHP 类的 mount 函数中,可以像这样传递值:
public $users = [];
public function mount()
{
$this->users['country_code'] = optional(user())->country_code;
$this->users['phone_no'] = optional(user())->phone_no;
}
如果您想设置 Livewire 的公共属性,可以这样做:
@push('dashboard-js')
<script>
phone_no.addEventListener('telchange', function(e) {
@this.set("users.phone_no", e.detail.validNumber);
@this.set("users.country_code", e.detail.dialCode);
});
</script>
@endpush
英文:
By doing following I have achieved what I want to do
in a blade file
<x-tel-input
wire:model="users.phone_no"
id="phone_no"
name="phone_no"
class="form-input numeric form-control form-control-lg"
/>
<input wire:model="users.country_code" type="hidden" id="country_code" name="country_code">
and in a PHP class mount function pass the values like this
public $users = [];
public function mount()
{
$this->users['country_code'] = optional(user())->country_code;
$this->users['phone_no'] = optional(user())->phone_no;
}
and also if you want to set livewire public property you can do this
@push('dashboard-js')
<script>
phone_no.addEventListener('telchange', function(e) {
@this.set("users.phone_no", e.detail.validNumber);
@this.set("users.country_code", e.detail.dialCode);
});
</script>
@endpush
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论