【问题标题】:how show input and hide input at same time with conditon from database ,如何根据数据库中的条件同时显示输入和隐藏输入,
【发布时间】:2021-04-09 16:56:53
【问题描述】:
<select class="form-control" wire:model.defer="production_parametre_fixes_id.0" wire:change="showUnite(0)">
    <option value="0">Choisir</option>
    @foreach ($list_parametres as $item)
        <option value="{{ $item->id }}">
            @if ($item->etape = 'Réception')
                {{ $item->matiere }}  |  {{ $item->unite }}
            @endif
       </option>
    @endforeach
</select>
<input type="text" class="form-control" placeholder=" " wire:model.defer="qte_materiel.0"/>
<input type="time" class="form-control" placeholder=" " wire:model.defer="debut.0"/>

我已经从数据库中选择,我想要

  • 如果unite 等于KGl,则仅显示quantite 的输入。
  • 如果unite 等于h,则显示heure 的输入。

我该怎么做?

【问题讨论】:

  • 你的问题不清楚
  • 也许您可以选择所有插入,然后循环查询响应,同时使用 if 语句检查 unite eagle 是 KR、l 还是 h。
  • 那么您的代码有什么问题?我只在这一行中看到一个缺失的相等: ($item->etape = 'Réception') 应该是两个 ==

标签: php laravel laravel-livewire alpine.js livewires


【解决方案1】:

如果变量 $unite 是从控制器发送的

@if($unite == 'KG' || $unite == 'l')
<input id="quantite" class="form-control"/>
@elseif($unite == 'h')
<input id="heure" class="form-control"/>
@endif

但如果你想根据所选项目做出决定,那么使用 [JQuery] 会很有用

您可以访问 https://www.w3schools.com/jquery/jquery_hide_show.asp

【讨论】:

  • 我必须在 foreach 中遇到问题
  • erreur in production_parametre_fixes_id.{{$value}} 当我只写 production_parametre_fixes_id 她在工作
  • 但是 production_parametre_fixes_id.{{$value}} 有一个块显示/隐藏输入
【解决方案2】:
                            <div class="row" x-data="">
                                <div class="col-md-1">
                                    <div class="form-group"  >
                                        <button type="button" class="btn btn-sm font-weight-bolder btn-light-primary"  wire:click.prevent="addmat()"><i class="la la-plus"></i></button>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <div class="input-group input-group-prepend">
                                            <div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-cogs icon-lg"></i></span></div>

                                            <select class="form-control"  wire:model.defer="production_parametre_fixes_id.0" wire:change="showUnite(0)" >
                                                <option  value="0"> Choisir </option>
                                                @foreach ($list_parametres as $item)
                                                    <option value="{{ $item->id }}">
                                                        @if($item->etape = 'Réception' )
                                                            {{ $item->matiere }}  |  {{ $item->unite }}
                                                        @endif
                                                    </option>
                                                @endforeach
                                            </select>
                                            <label>{{ __('Matériel') }}</label>
                                        </div>
                                        @error('production_parametre_fixes_id')
                                        <span class="form-text text-danger">{{ $message }}</span>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group" x-show="$wire.showmatiere[0]">
                                        <div class="input-group input-group-prepend">
                                            <div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-shopping-basket icon-lg"></i></span></div>
                                            <input type="text" class="form-control" placeholder=" " wire:model.defer="qte_materiel.0"/>
                                            <label>{{ __('Qte') }}</label>
                                        </div>
                                        @error('qte_materiel')
                                        <span class="form-text text-danger">{{ $message }}</span>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group" x-show="$wire.showheure[0]">
                                        <div class="input-group input-group-prepend">
                                            <div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-history icon-lg"></i></span></div>
                                            <input type="time" class="form-control" placeholder=" " wire:model.defer="debut.0"/>
                                            <label>{{ __('Début') }}</label>
                                        </div>
                                        @error('debut')
                                        <span class="form-text text-danger">{{ $message }}</span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-3">
                                    <div class="form-group" x-show="$wire.showfin[0]">
                                        <div class="input-group input-group-prepend">
                                            <div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-history icon-lg"></i></span></div>
                                            <input type="time" class="form-control" placeholder=" " wire:model.defer="fin.0"/>
                                            <label>{{ __('Fin') }}</label>
                                        </div>
                                        @error('fin')
                                        <span class="form-text text-danger">{{ $message }}</span>
                                        @enderror
                                    </div>
                                </div>
                            </div>
                        </div>
                        @foreach ($inputsmat as $key  => $value)

                            <div class="container">
                                <div class="row" x-data="">
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <div class="input-group input-group-prepend">
                                                <div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-cogs icon-lg"></i></span></div>
                                                <select class="form-control"  wire:model.defer="production_parametre_fixes_id.{{$value}}" wire:change="showUnite({{$value}})"  >
                                                    <option  value="0"> Choisir </option>
                                                    @foreach ($list_parametres as $item)
                                                        <option value="{{ $item->id }}">
                                                            @if($item->etape = 'Réception')
                                                                {{ $item->matiere }}  |  {{ $item->unite }}
                                                            @endif</option>
                                                    @endforeach
                                                </select>
                                                <label>{{ __('Matériel') }}</label>
                                            </div>
                                            @error('production_parametre_fixes_id')
                                            <span class="form-text text-danger">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group" x-show="$wire.showmatiere[{{$value}}]" :key="'q-'.$value">
                                            <div class="input-group input-group-prepend" >
                                                <div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-shopping-basket icon-lg"></i></span></div>
                                                <input type="text" class="form-control" placeholder=" " wire:model.defer="qte_materiel.{{$value}}"/>
                                                <label>{{ __('Qte') }}</label>
                                            </div>
                                            @error('qte_materiel')
                                            <span class="form-text text-danger">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group" x-show="$wire.showheure[{{$value}}]" :key="'d-'.$value">
                                            <div class="input-group input-group-prepend">
                                                <div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-history icon-lg"></i></span></div>
                                                <input type="time" class="form-control"  placeholder=" " wire:model.defer="debut.{{$value}}"/>
                                                <label>{{ __('Début') }}</label>
                                            </div>
                                            @error('debut')
                                            <span class="form-text text-danger">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group" x-show="$wire.showfin[{{$value}}]" :key="'f-'.$value">
                                            <div class="input-group input-group-prepend">
                                                <div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-history icon-lg"></i></span></div>
                                                <input type="time" class="form-control" placeholder=" " wire:model.defer="fin.{{$value}}"/>
                                                <label>{{ __('Fin') }}</label>
                                            </div>
                                            @error('debut')
                                            <span class="form-text text-danger">{{ $message }}</span>
                                            @enderror
                                        </div>
                                    </div>
                                    <div class="col-md-1">
                                        <div class="form-group" >
                                            <button type="button" class="btn btn-outline-danger"  wire:click.prevent="removeMat({{$key}})">X</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        @endforeach```
controller:
public function showUnite($myLine)
    {
        $para = ProductionParametreFixe::query()->where('id',$this->production_parametre_fixes_id)->first();

        if($para->unite == "Kg" || $para->unite == "L"){
            $this->showmatiere[$myLine] = true ;
            $this->showheure[$myLine] = false;
            $this->showfin[$myLine] = false;

        }else if($para->unite == "H"){

            $this->showheure[$myLine] = true;
            $this->showfin[$myLine] = true;
            $this->showmatiere[$myLine] = false ;

        }
       
    }

【讨论】:

    猜你喜欢
    • 2017-04-01
    • 2012-06-15
    • 2013-07-22
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多