4

i had one search box in inside modal body . i created one search option for modal i had the result also but outside of modal search working fine but inside modal search results couldn't display any ideas?

My Modal Code :

<div id="myModal" class="modal fade" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                <div id="job-title-select2" style="display:none;">
                    <div class="form-group">
                        <input type="text" id="jobsearch" name="jobsearch" class="form-control" value="" placeholder="Enter Job Title....">
                        <input type="submit" id="title-button" class="btn btn-info btn" value="Confirm">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

jquery code :

$("#jobsearch").autocomplete({
        source: function(request, response) {
                $.ajax({
                    url: "{{route('searchexistingjob')}}",
                    dataType: "json",
                    data: {term : request.term},
                    success: function(data) {
                         /////
                    }
                });
            },
        minLength: 3,
});

output result in console :

[{id: 6, value: "Analytical thinker"}]

controller return value :

array (

0 => array ( 'id' => 6, 'value' => 'Analytical thinker', ), )

so i need to display the value.

Sivaraju Mani
  • 195
  • 12
  • I have posted the answer let me know if there is any confusion. – Umar Majeed Dec 20 '17 at 10:47
  • 2
    The first question is where do you want the results to be displayed? – RiggsFolly Dec 20 '17 at 10:49
  • Create an empty DIV in your modal to hold the result of the search and then place `date.id` and `data.value` into this blank DIV – RiggsFolly Dec 20 '17 at 10:55
  • but how to select that value again and process ex: if the value was john means again i can process that form how this display workes like selection option? – Sivaraju Mani Dec 20 '17 at 10:58
  • please provide snippet if possible so we can check what is the exact problem – Prateik Darji Dec 20 '17 at 11:24
  • snippet was not possible because data problem - see am searching some data using autocomplete search - am typing some words means it will display matched value from database but this this works only in outside of modal but am doing inside modal means it will not display – Sivaraju Mani Dec 20 '17 at 11:32
  • are you able to view the text box in modal? – Prateik Darji Dec 20 '17 at 11:43
  • yes - https://stackoverflow.com/questions/16133654/autocomplete-issue-into-bootstrap-modal i need result like this - i tried but not displaying u have any idea means tell me – Sivaraju Mani Dec 20 '17 at 11:46

2 Answers2

1

Assuming your server side data will be like

$data = array (array ( 'id' => 6, 'value' => 'Analytical thinker'));
echo json_encode($data);

And in your ajax success pass your data back to ajax source response like below.

response(data);

So your ajax code will be,

$.ajax({
    url: "{{route('searchexistingjob')}}",
    dataType: "json",
    data: {term : request.term},
    success: function(data) {
        response(data);
    }
});

Note: If all works fine but still not displaying surely z-index causing the problem. So add below style and try,

.ui-autocomplete {
    position:absolute;
    cursor:default;
    z-index:4000 !important
}
Elumalai Kaliyaperumal
  • 1,498
  • 1
  • 12
  • 24
-1

use the below code in your success function

    obj = JSON.parse(data);

    $("#jobsearch").val(obj.value);
    $("#job-title-select2").show();
    $('#myModal').modal('show'); 
Umar Majeed
  • 313
  • 3
  • 15