-1

Here is my situation i am trying to get a pop-up/modal form when the user click a button.I am getting the form data from Link but i don't know how to approach it. basically i can create a modal using bootstrap but the problem is i can't integrate this Jquery with the bootstrap modal. So how to approach this problem.help me i am stuck.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
        crossorigin="anonymous">
</head>

<body>

    <div class="container">
        <button class="btn btn-primary btn-action" data-url="/echo?someval=mydatavalue1" id="btnAction1">Button API Call 1</button>
        <button class="btn btn-primary btn-action" data-url="/echo?someval=mydatavalue2" id="btnAction2">Button API Call 2</button>
        <div id="myModal" class="modal fade" tabindex="-1" role="dialog">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Modal</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    </div>
                    <div class="modal-body">
                    </div>
                    <div class="modal-footer">
                    </div>
                </div>
            </div>
        </div>
    </div>

    <h1>Getting started with JSON Form</h1>
    <form></form>
    <div id="res" class="alert"></div>


    <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em"
        crossorigin="anonymous"></script>
    <!-- <script type="text/javascript" src="deps/jquery.min.js"></script> -->
    <script type="text/javascript" src="deps/underscore.js"></script>
    <script type="text/javascript" src="deps/opt/jsv.js"></script>
    <script type="text/javascript" src="lib/jsonform.js"></script>

    <script type="text/javascript" >
    $(document).ready(function () {

    var test = function x() {
        $('form').jsonForm({
            schema: {
                name: {
                    type: 'string',
                    title: 'Name',
                    required: true
                },
                age: {
                    type: 'number',
                    title: 'Age'
                }
            },
            onSubmit: function (errors, values) {
                if (errors) {
                    $('#res').html('<p>I beg your pardon?</p>');
                } else {
                    $('#res').html('<p>Hello ' + values.name + '.' +
                        (values.age ? '<br/>You are ' + values.age + '.' : '') +
                        '</p>');
                }
            }
        });
    }

    $('.btn-action').click(function () {
        // update modal content
        $('.modal-body').html(test())
        // // show modal
        $('#myModal').modal('show');
    });
});
    
    </script>

</body>

</html>

At the end what i want is when i click the button the modal should open with the Form data above. I don't know weather i am approaching it right or not feel free to suggest me any other solution to this i am a beginner and this is my work in a job.

DeadlyDev
  • 77
  • 1
  • 1
  • 6

1 Answers1

1

$ is not defined means jquery library is not found, check the dependencies, JSON Form library depends on jQuery, try adding the jQuery library

stackmalux
  • 77
  • 11