Tuesday, March 13, 2018

JavaScript library doesn’t load - development

JavaScript library doesn’t load

I have this friend who want some changes made on his website. It developed in Laravel which I’ve never used before.

There’s this master.blade with @yield('scripts') but when I add stuff to the section in the view it doesn’t load?

Here’s the master.blade.

<!DOCTYPE html>

<html lang="">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="">

    <title></title>
    <title>@yield('title')</title>
    <!-- Styles -->


    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="" rel="stylesheet">
    @yield('datetimepicker')
</head>
<body>
    <div id="app">
        @if(!isset($remove_navbar))
            @include('layouts.navbar')
        @endif   
        <div class="container">
            @if ($flash = session('message'))
                <div id="flash-message" class="alert alert-success">
                    
                </div>
            @endif

            @yield('content')
        </div>
    </div>
    <!-- Scripts -->
    <script src=""></script>
    <script
    src="https://code.jquery.com/jquery-3.2.1.min.js"
    integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
    crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

    @yield('scripts')

    </body>
</html>

And here’s the view

@extends('layouts.master')

@section('datetimepicker')
<link href="https://cdnjs.cloudflare.com/ajax/libs/smalot-bootstrap-datetimepicker/2.4.4/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
@endsection

@section('content')
<div class="container">
    <div class="col-xs-12 col-sm-12 col-md-offset-1 col-md-10 col-lg-offset-2 col-lg-8">

        <h3></h3>
        <h4></h4>
        <form method="post" action="">
        
        @foreach($questions as $i => $question)
        <?php $answer=AppAnswer::where('recipient_id','=',$recipient->id)->where('question_id','=',$question->id)->get()->first(); ?>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"></h3>
            </div>
            <div class="panel-body">
                <p></p>

                @if($answer->question->type=='2')



                <div class="" id="grad">
                    @for($j=1;$j<=10;$j++)  
                    <label> 
                        <input type="radio" value="" 
                         >
                    </label>
                    @endfor 

                </div>  
                @endif
                @if($answer->question->type=='2')
                <p></p>
                @else
            <p>Medarbejderen svarede:</p>
            @endif
            <p><strong></strong></p>




        </div>

        <div class="panel-footer">

        @if($answer->question->type=='2')
        <p>Mål</p>
            <div class="" id="grad">

                        @for($j=1;$j<=10;$j++)  
                        <label> 
                            <input type="radio" name="interval_" value="" 
                            >
                        </label>
                        @endfor     

        </div>
        @endif


        <br>
        <div class="form-group">
            <textarea rows="4" name="text_" class="form-control" placeholder="Du kan skrive en note om indsatsen her"></textarea>


        @if ($errors->has('text_'.$i))
        <span class="help-block">
            <strong>Skriv venligst dit svar i tekstfeltet.</strong>
        </span>
        @endif
        </div>


        </div>
    </div>
    <br>
    @endforeach


    <div class="panel panel-default">

        <div class="panel-body">
            <label>Skal opfølges <input type="checkbox" id="checkbox" name="followup" ></label>
            <input size="16" type="text" readonly class="form_datetime hidden" placeholder="Opfølgningsdato" value="" style="margin-left: 20px;" name="followupdate">
            <button type="submit" class="btn btn-primary pull-right">Gem og vis opfølgning</button>
            </form>
        </div>
    </div>
</div>
</div>   
@endsection

@section('scripts') 
<script src="https://cdnjs.cloudflare.com/ajax/libs/smalot-bootstrap-datetimepicker/2.4.4/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript">
$(".form_datetime").datetimepicker({
    format: 'dd-mm-yyyy hh:ii',
    autoclose: true,
    pickerPosition: "top-right"
})

if($("#checkbox").is(':checked')){
    $('.form_datetime').removeClass('hidden')
}

$("#checkbox").on('change', function() {
    if ( this.checked ) {
        $('.form_datetime').removeClass('hidden')
    } else {
        $('.form_datetime').addClass('hidden')
    }
})
</script>
@endsection

The problem is that the custom jQuery and bootstrap-datetimepicker.js doesn’t load.

Does anyone know why? – If you need more code let me know! 🙂

EDIT 1:
Found out if I look in the code (CTRL+U) the <script>-tags are there and the jQuery is there but doesn’t work. If I look in the inspector (CTRL+SHIFT+I) it’s not there.



from Laravel Questions and Answers https://laravelquestions.com/laravel/javascript-library-doesnt-load/
via Lzo Media

No comments:

Post a Comment