evripidesk's avatar

Laravel Blade and Javascript

Hello I have the below blade with datepicker but is not working the datepicker (no error in concole)

@extends('layouts.app')


  <head>
    <title></title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>  
    <meta name="csrf-token" content="{{ csrf_token() }}">

</head>
@section('content')
  <body>

    <div class="container">
     

      @if ($errors->any())
      <div class="alert alert-danger">
          <ul>
              @foreach ($errors->all() as $error)
                  <li>{{ $error }}</li>
              @endforeach
          </ul>
      </div><br />
      @endif

      <form method="post" action="{{action('EmployeesController@createJobTitle')}}">

        <input name="date" class="date form-control" type="text">


      </form>

    </div>
@endsection
  </body>
<script type="text/javascript">

  $('.date').datepicker({  

     format: 'mm-dd-yyyy'

   });  

</script> 

if I dont use the endsection then is working but is breaking the template

0 likes
7 replies
ftiersch's avatar

You are extending a template so you can only use the sections that template offers you. Remove the stuff before @section and after @endsection

bballantyne's avatar

What would you have before the in your layouts blade? I''m just trying to understand how your template would be structured.

artcore's avatar

Wrap it inside a dom ready event?

document.addEventListener('DOMContentLoaded', function(){

   $('.date').datepicker({  

     format: 'mm-dd-yyyy'

   });

});
Ashraam's avatar

Try to put the script code inside the body tag

Snapey's avatar
Snapey
Best Answer
Level 122

only the code inside section will be in the rendered page

also, have you removed references to app.js in the layout file, since if not then you have jquery loaded twice

Please or to participate in this conversation.