【问题标题】:Laravel 8: keep modal open if there are errorsLaravel 8:如果有错误,保持模式打开
【发布时间】:2021-12-31 02:20:01
【问题描述】:

如果有错误,我想让模态保持打开状态,但是出现错误时模态不会自动打开

    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
    <script src="//unpkg.com/alpinejs" defer></script>
    <script src="{{ url('/js/jquery.min.js') }}"></script>
    <script src="js/bootstrap.min.js"></script>
   

 @if($errors->any())
       <script type="text/javascript">  
            $(document).ready(function(){ 
            $('#modal-title').modal('show');   
            });   
     </script>              
  @endif

模态

    <form action="/employee" class="action" method="POST">
        @csrf
        <div class="fixed z-10 inset-0 overflow-y-scroll" aria-labelledby="modal-title" id="modal-title" role="dialog" aria-modal="true"
            x-show="open">

【问题讨论】:

  • 你应该为此使用 ajax
  • @Umer Fayyaz 你能告诉我如何使用 ajax 吗?

标签: laravel error-handling modal-dialog bootstrap-modal laravel-8


【解决方案1】:

试试这个

<script type="text/javascript">
@if (count($errors) > 0)
    $('#modal-title').modal('show');
@endif
</script>

【讨论】:

  • 出现错误时仍然不会保持模态打开
  • 好方法是使用ajax。你可以在这里找到如何使用它的简单youtube.com/watch?v=CFhnxnJ7pLU
  • 我关注视频仍然失败@Umer Fayyaz
  • @ Umer Fayyaz 这是我的代码
猜你喜欢
  • 1970-01-01
  • 2023-03-13
  • 1970-01-01
  • 2022-01-27
  • 1970-01-01
  • 2016-04-17
  • 2014-04-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多