dsavz66262 2018-09-07 07:47
浏览 61
已采纳

如果变量为空,则禁用按钮

So I have this forelse that displays all the variants, now what I want to happen is that, if there is no variant. the submit button will be disabled.

                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th class="col-sm-5">Name</th>
                                    <th class="col-sm-1">Default?</th>
                                    <th class="col-sm-2 text-right">Retail Price</th>
                                    <th class="col-sm-2 text-right">Quantity</th>
                                    <th class="col-sm-2"></th>
                                </tr>
                            </thead>
                            <tbody>
                            @forelse ($product->variants as $index => $variant)
                                <tr>
                                    <td>{{ $variant->name }}</td>
                                    <td>{{ $variant->is_default ? 'Yes' : 'No' }}</td>
                                    <td class="text-right">{{ number_format($variant->retail_price, 2) }} {{ $variant->price_currency }}</td>
                                    <td class="text-right">{{ number_format($variant->quantity, 0) }}</td>
                                    <td><a href="{{ route('developer.variants.edit', [$store->slug, $product, $variant]) }}" class="btn btn-xs btn-default pull-right">Edit</a></td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="5">No variants found</td>
                                    <?php $varbutton = 'disabled';?>
                                </tr>
                            @endforelse
                            </tbody>
                        </table>

here is the button

<div class="panel-footer">
  <button class="btn btn-default" type="submit"<?php $varbutton; ?>>Update Store</button>
</div>

Is it possible using php and html in the blade alone or do I have to do it in the controller?

  • 写回答

1条回答 默认 最新

  • douzhenqun1271 2018-09-07 07:52
    关注

    You should be using blade in your button:

    <div class="panel-footer">
      <button class="btn btn-default" type="submit" {{ $varbutton }}>Update Store</button>
    </div>
    

    Also please note that there needs to be a space after "submit".

    Or, if you don't want that space when the button is not disabled, use:

    <?php $varbutton = ' disabled';?>
    <div class="panel-footer">
      <button class="btn btn-default" type="submit"{{ $varbutton }}>Update Store</button>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化