admin管理员组

文章数量:1125422

here i'm calling fetchActivityDropDowns() inside div data are comming correctly but [object promise] are showing just before choose accommodation type stip so how can resolve?

Basically i had created a seprate async fucntion to fetchdropdowns data from server and i also calling other async fucntion inside ansyc function so that I'm getting this kind of error I want to solev this how can?

async function fetchDaywiseActivityAndAccomData(subqId, daywiseIdPK) {

        if (subqId && daywiseIdPK) {

            showLoader('Please Wait!', 'Fetching activities and accommodation!');

            try {
                const response = await $.ajax({
                    url: "{{ url('/quoteactivityplanner/get-daywise-act-and-accom-data') }}",
                    method: "POST",
                    headers: {
                        "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                    },
                    data: {
                        "subqId": subqId,
                        "daywiseIdPK": daywiseIdPK,
                    },
                    dataType: "json"
                });


                if (response.status === 'true') {

                    const {
                        mealProviders,
                        mealSlots,
                        meals,
                        accom_cat_list
                    } = response.data;
                    const itineraryCardData = response?.data?.quote_daywise_data[0];
                    
                    const activityCount = itineraryCardData?.activities?.length || 0;
                    // for btn if no any activity then 
                    const activityButton = activityCount === 0
                        ? `
                            <button class="btn btn-primary pull-left add-activity" style="margin-right: 10px;" 
                                data-day-id="${itineraryCardData.day_id}" 
                                data-accom-day-id="${itineraryCardData.daywise_id_pk}" 
                                data-country-id="${itineraryCardData.country_id}">
                                <i class="fa fa-plus mx-1"></i><span>Add Activity</span>
                            </button>
                        `
                        : '';
               
                    const daywiseActCard = document.querySelector('.daywise-act-block');
                    let actDayCard = ` 
                        <div class="col-xl-12 col-lg-12 col-md-12 mb-1 act-day-card" id="itinerary_day_card_${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}" data-day_id=${itineraryCardData.day_id}">
                            <div class="card m-0 daywise-act-card rounded">
                                <div class="col-12 p-0 bg-grey rounded-top">
                                    <p class="p-1 mb-0 text-white">
                                        Day ${itineraryCardData.day_id} - Itinerary
                                        <span class="pull-right">${new Date(itineraryCardData.day_date).toLocaleDateString('en-GB')}</span>
                                    </p>
                                </div>
                                <div class="col-12 p-0">
                                    <div class="row m-0">
                                        <div class="col-12">
                                            <div class="row">
                                                <div class="col-10 mt-1 Actionbtns">
                                                    <button class="btn btn-primary pull-left add-accom-day-before" style="margin-right: 10px;" data-day-id=${itineraryCardData.day_id} data-daywiseid=${itineraryCardData.daywise_id_pk} data-subquoteid=${itineraryCardData.sub_id} ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}>
                                                        <i class="fa fa-plus mx-1"></i><span>Add A day Before</span>
                                                    </button>
                                                    <button class="btn btn-primary pull-left add-tour-day-before" 
                                                        style="margin-right: 10px;" 
                                                        data-day-id="${itineraryCardData.day_id}" 
                                                        data-daywiseid="${itineraryCardData.daywise_id_pk}" 
                                                        data-subquoteid="${itineraryCardData.sub_id}" 
                                                        data-before="0"
                                                        data-target="#modal_add_tour_day_after_before" 
                                                        data-toggle="modal" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}>
                                                        <i class="fa fa-plus mx-1"></i><span>Add Tour's Days Before</span>
                                                    </button>
                                                    <button class="btn btn-primary pull-left copy-quote-itinerary-before" 
                                                        style="margin-right: 10px;" 
                                                        data-day-id="${itineraryCardData.day_id}" 
                                                        data-daywiseid="${itineraryCardData.daywise_id_pk}" 
                                                        data-subquoteid="${itineraryCardData.sub_id}" 
                                                        data-before="0"
                                                        data-target="#copy_quote_itinerary" 
                                                        data-toggle="modal" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}>
                                                        <i class="fa fa-plus mx-1"></i><span>Copy Quote's Itinerary Before</span>
                                                    </button>
                                                    ${activityButton}
                                                </div>
                                                <div class="col-2 mt-1">
                                                    <a target="_blank" href="{{ url('quote/additional_activity/add/${itineraryCardData.sub_id}/${itineraryCardData.daywise_id_pk}') }}" >
                                                        <button class="btn btn-success pull-right submit_quote" title="Add Optional Activity" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}>
                                                            <i class="fa fa-plus mx-1"></i><span>Add Optional Activity</span>
                                                        </button>
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="p-1">
                                    <div class="itinerary-form-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk} itinerary-day-block rounded">
                                        <!-- Activity Section Start -->
                                        ${
                                            // Generate the activity HTML content here
                                            itineraryCardData?.activities.map(item => `
                                                <!-- Activity Section Start -->
                                                <form id="update-activity-form-${itineraryCardData.day_id}-${item.activity_id_pk}" method="POST"  style="${item.activity_id_pk ? 'display: block;' : 'display: none;'}" class="mb-1"  class="individual-activity-form">
                                                    <div class="activity-section p-1 rounded">
                                                        <div class="row">
                                                            <div class="col-10 mt-1">      
                                                                <button class="btn btn-primary pull-left add-activity-before" style="margin-right: 10px;" data-day-id="${itineraryCardData.day_id}" data-accom-day-id="${itineraryCardData.daywise_id_pk}" data-activity-id="${item.activity_id_pk}"  data-country-id="${itineraryCardData.country_id}" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}>
                                                                    <i class="fa fa-plus mx-1"></i><span>Add Activity Before</span>
                                                                </button>
                                                            </div>
                                                            <div class="col-2 mt-1">
                                                                <!--
                                                                <a target="_blank" href="{{ url('quote/additional_activity/add/17741/167564') }}">
                                                                    <button class="btn btn-success pull-right submit_quote" title="Add Additional Activity">
                                                                        <i class="fa fa-plus mx-1"></i><span>Add Optional Activity</span>
                                                                    </button>
                                                                </a>
                                                                -->
                                                            </div>
                                                        </div>

                                                        <div class="row g-3">
                                                            <div class="col-12 mt-1">   
                                                                <p class="p-1 mb-0 day-activity-name p-1 text-center">
                                                                    ${item.activity_name ? item.activity_name : 'NA'}
                                                                </p>   
                                                            </div>
                                                            <!-- City -->
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="city">City</label>
                                                                <select name="act_city_id_fk" id="act_city_id_fk-${itineraryCardData.day_id}-${item.activity_id_pk}" data-day-id=${itineraryCardData.day_id} data-activity-id=${item.activity_id_pk} class="form-control change_activity_city" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}></select>
                                                            </div>
                                                            <!-- City Image -->
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="cityImage">City Image</label>
                                                                <select name="city_image_id_fk" id="city_image_id_fk-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}></select>
                                                            </div>
                                                            <!-- Activity -->
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="activity">Activity</label>
                                                                <select name="city_activity_id_fk" id="city_activity_id_fk-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}></select>
                                                            </div>
                                                        </div>

                                                        <div class="row g-3 mt-1">
                                                            <!-- Activity Provider -->  
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="activityProvider">Activity Provider</label>
                                                                <select name="activity_provider_id_fk" id="activity_provider_id_fk-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}></select>
                                                            </div>
                                                            <!-- Activity Timing -->
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="activityTiming">Activity Timing</label>
                                                                <div class="row g-2">
                                                                    <div class="col-6 d-flex align-items-center">
                                                                        <span>From:</span>
                                                                        <input name="act_start_time" type="time" id="act-start-time-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control mx-1" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                                    </div>
                                                                    <div class="col-6 d-flex align-items-center">
                                                                        <span>To:</span>
                                                                        <input name="act_end_time" type="time" id="act-end-time-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control mx-1" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <!-- Kilometer -->
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="kilometer">Kilometer</label>
                                                                <input type="text" name="act_kilometer" id="act-kilometer-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control" placeholder="Enter kilometers" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''} />
                                                            </div>
                                                        </div>

                                                      
                                                    </div>
                                                </form>
                                                <!-- Activity Section End -->
                                                
                                                ${fetchActivityDropDowns(itineraryCardData.country_id, itineraryCardData.day_id, item)}
                                            `   
                                            ).join('')

                                        }    
                                        <!-- Activity Section End -->

                                        <!-- Accomodation Section Start -->
                                        <form id="update-accommodation-form-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}"  method="POST">
                                            <div class="accomodation-section p-2 mt-1 rounded">
                                                <div class="bg-success rounded accom-type-switch text-white">
                                                    <div class="row pb-1">
                                                        <div class="col-3 custom-control enxtyuepp custom-switch">
                                                            <b>Choose Accommodation Type :</b>
                                                        </div>
                                                        <div class="col-1 custom-control enxtyuepp custom-switch">
                                                            <input type="radio" name="own_accom" class="custom-control-input accom-type" data-day_id="${itineraryCardData.day_id}" data-accom_day_id="${itineraryCardData.daywise_id_pk}" id="hotelSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}" value="0" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                            <label class="custom-control-label text-white" for="hotelSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}">
                                                                <span>Hotel</span>
                                                            </label>
                                                        </div>
                                                        <div class="col-1 custom-control enxtyuepp custom-switch">
                                                            <input type="radio" name="own_accom" class="custom-control-input accom-type" data-day_id="${itineraryCardData.day_id}" data-accom_day_id="${itineraryCardData.daywise_id_pk}" id="trainSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}" value="2" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                            <label class="custom-control-label text-white" for="trainSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}">
                                                                <span>Train</span>
                                                            </label>
                                                        </div>
                                                        <div class="col-1 custom-control enxtyuepp custom-switch">
                                                            <input type="radio" name="own_accom" class="custom-control-input accom-type" data-day_id="${itineraryCardData.day_id}" data-accom_day_id="${itineraryCardData.daywise_id_pk}" id="flightSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}" value="3" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                            <label class="custom-control-label text-white" for="flightSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}">
                                                                <span>Flight</span>
                                                            </label>
                                                        </div>
                                                        <div class="col-3 custom-control enxtyuepp custom-switch">
                                                            <input type="radio" name="own_accom" class="custom-control-input accom-type" data-day_id="${itineraryCardData.day_id}" data-accom_day_id="${itineraryCardData.daywise_id_pk}" id="ownArrangementSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}" value="1" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                            <label class="custom-control-label text-white" for="ownArrangementSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}">
                                                                <span>Own Arrangement</span>
                                                            </label>
                                                        </div>
                                                    </div>
                                                </div>
                                    
                                        

                                                <!-- Update day Button END -->
                                            </div>
                                        </form>
                                        <!-- End of Accomodation Section -->
                                    </div>
                                </div>
                            </div>
                        </div>
                    `;
                    $('.daywise-act-block').append(actDayCard);

                  

                }

            } catch (error) {
                Swal.fire({
                    icon: "error",
                    title: 'Oops...',
                    text: 'AJAX' + error,
                });
            }
        } else {
            Swal.fire({
                icon: "error",
                title: 'Oops...',
                text: 'No data found.',
            });
        }
    }

this is the second function which I'm calling inside other function

  async function fetchActivityDropDowns(countryId, dayId, activityData) {

        try {

            // AJAX request to fetch activity dropdown data
            const response = await $.ajax({
                url: "{{ url('/quoteactivityplanner/getActivityDropdowns') }}",
                method: "POST",
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                },
                data: { countryId: countryId },
                dataType: "json"
            });

            // Extracting data from the response
            const { cities, cityImages, cityActivities, activityProviders, transportTypes, transportProviders, guideProviders, miscellaneous } = response.data;

            // Populating the city dropdown
            if (cities) {
                const cityDropdown = $(`#act_city_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                
                // Clear previous options and add the default option
                cityDropdown.html('<option value="">Select City</option>');
                
                // Populate the dropdown with city options
                $.each(cities, function(cId, cityName) {
                    const option = new Option(cityName, cId, false, cId == activityData.activity_city_id);
                    cityDropdown.append(option);
                });

                // Initialize or reinitialize Select2
                cityDropdown.select2({
                    placeholder: 'Select City',
                    allowClear: true,
                    width: '100%'
                }).trigger('change');

                // Listen for city selection changes
                cityDropdown.on('change', function () {
                  
                    const selectedCityId = $(this).val();
                    const selectedCityName = $(this).find(':selected').text();
                    $(`.act-accom-city-name-${dayId}`).html(`(${selectedCityName || 'No City updated'})`);

                    // Get the related activity dropdown
                    const activityDropdown         = $(`#city_activity_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                    const cityImageDropdown        = $(`#city_image_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                    const activityProviderDropdown = $(`#activity_provider_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                    const transportProviderDropdown= $(`#transport_provider_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                    const guideProviderDropdown    = $(`#guide_provider_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                    
                    if (!selectedCityId) {
                        // If no city is selected, clear and disable the activity dropdown
                        // activityDropdown.html('<option value="">Select City Activity</option>').prop('disabled', true);
                        activityDropdown.html('<option value="">Select City Activity</option>').select2().trigger('change');
                        cityImageDropdown.html('<option value="">Select City Image</option>').select2().trigger('change');
                        activityProviderDropdown.html('<option value="">Select Activity Provider</option>').select2().trigger('change');
                        transportProviderDropdown.html('<option value="">Select Transport Provider</option>').select2().trigger('change');
                        guideProviderDropdown.html('<option value="">Select Guide Provider</option>').select2().trigger('change');
                        
                    } else {
                        // If a city is selected, enable the activity dropdown and trigger the function to populate it
                        // activityDropdown.prop('disabled', false);
                        // Call your function to populate activities for the selected city
                        fetchCityActivities(selectedCityId, activityDropdown, cityImageDropdown, activityProviderDropdown, transportProviderDropdown, guideProviderDropdown);
                    }
                });
            }

           
            // Populating input fields with activity data
            $(`#description-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).text(activityData.activity_description || '');
            $(`#act-kilometer-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.act_kilometer);
            $(`#approx-drive-hour-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.approx_drive_hour);
            $(`#approx-drive-min-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.approx_drive_min);
            $(`#act-start-time-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.act_start_time);
            $(`#act-end-time-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.act_end_time);
            $(`#transport-details-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.transport_details);
            $(`#activity-notes-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.act_sub_description);

        } catch (error) {
            console.error('Error fetching activity dropdowns:', error);
        }
    }

here i'm calling fetchActivityDropDowns() inside div data are comming correctly but [object promise] are showing just before choose accommodation type stip so how can resolve?

Basically i had created a seprate async fucntion to fetchdropdowns data from server and i also calling other async fucntion inside ansyc function so that I'm getting this kind of error I want to solev this how can?

async function fetchDaywiseActivityAndAccomData(subqId, daywiseIdPK) {

        if (subqId && daywiseIdPK) {

            showLoader('Please Wait!', 'Fetching activities and accommodation!');

            try {
                const response = await $.ajax({
                    url: "{{ url('/quoteactivityplanner/get-daywise-act-and-accom-data') }}",
                    method: "POST",
                    headers: {
                        "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                    },
                    data: {
                        "subqId": subqId,
                        "daywiseIdPK": daywiseIdPK,
                    },
                    dataType: "json"
                });


                if (response.status === 'true') {

                    const {
                        mealProviders,
                        mealSlots,
                        meals,
                        accom_cat_list
                    } = response.data;
                    const itineraryCardData = response?.data?.quote_daywise_data[0];
                    
                    const activityCount = itineraryCardData?.activities?.length || 0;
                    // for btn if no any activity then 
                    const activityButton = activityCount === 0
                        ? `
                            <button class="btn btn-primary pull-left add-activity" style="margin-right: 10px;" 
                                data-day-id="${itineraryCardData.day_id}" 
                                data-accom-day-id="${itineraryCardData.daywise_id_pk}" 
                                data-country-id="${itineraryCardData.country_id}">
                                <i class="fa fa-plus mx-1"></i><span>Add Activity</span>
                            </button>
                        `
                        : '';
               
                    const daywiseActCard = document.querySelector('.daywise-act-block');
                    let actDayCard = ` 
                        <div class="col-xl-12 col-lg-12 col-md-12 mb-1 act-day-card" id="itinerary_day_card_${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}" data-day_id=${itineraryCardData.day_id}">
                            <div class="card m-0 daywise-act-card rounded">
                                <div class="col-12 p-0 bg-grey rounded-top">
                                    <p class="p-1 mb-0 text-white">
                                        Day ${itineraryCardData.day_id} - Itinerary
                                        <span class="pull-right">${new Date(itineraryCardData.day_date).toLocaleDateString('en-GB')}</span>
                                    </p>
                                </div>
                                <div class="col-12 p-0">
                                    <div class="row m-0">
                                        <div class="col-12">
                                            <div class="row">
                                                <div class="col-10 mt-1 Actionbtns">
                                                    <button class="btn btn-primary pull-left add-accom-day-before" style="margin-right: 10px;" data-day-id=${itineraryCardData.day_id} data-daywiseid=${itineraryCardData.daywise_id_pk} data-subquoteid=${itineraryCardData.sub_id} ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}>
                                                        <i class="fa fa-plus mx-1"></i><span>Add A day Before</span>
                                                    </button>
                                                    <button class="btn btn-primary pull-left add-tour-day-before" 
                                                        style="margin-right: 10px;" 
                                                        data-day-id="${itineraryCardData.day_id}" 
                                                        data-daywiseid="${itineraryCardData.daywise_id_pk}" 
                                                        data-subquoteid="${itineraryCardData.sub_id}" 
                                                        data-before="0"
                                                        data-target="#modal_add_tour_day_after_before" 
                                                        data-toggle="modal" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}>
                                                        <i class="fa fa-plus mx-1"></i><span>Add Tour's Days Before</span>
                                                    </button>
                                                    <button class="btn btn-primary pull-left copy-quote-itinerary-before" 
                                                        style="margin-right: 10px;" 
                                                        data-day-id="${itineraryCardData.day_id}" 
                                                        data-daywiseid="${itineraryCardData.daywise_id_pk}" 
                                                        data-subquoteid="${itineraryCardData.sub_id}" 
                                                        data-before="0"
                                                        data-target="#copy_quote_itinerary" 
                                                        data-toggle="modal" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}>
                                                        <i class="fa fa-plus mx-1"></i><span>Copy Quote's Itinerary Before</span>
                                                    </button>
                                                    ${activityButton}
                                                </div>
                                                <div class="col-2 mt-1">
                                                    <a target="_blank" href="{{ url('quote/additional_activity/add/${itineraryCardData.sub_id}/${itineraryCardData.daywise_id_pk}') }}" >
                                                        <button class="btn btn-success pull-right submit_quote" title="Add Optional Activity" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}>
                                                            <i class="fa fa-plus mx-1"></i><span>Add Optional Activity</span>
                                                        </button>
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="p-1">
                                    <div class="itinerary-form-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk} itinerary-day-block rounded">
                                        <!-- Activity Section Start -->
                                        ${
                                            // Generate the activity HTML content here
                                            itineraryCardData?.activities.map(item => `
                                                <!-- Activity Section Start -->
                                                <form id="update-activity-form-${itineraryCardData.day_id}-${item.activity_id_pk}" method="POST"  style="${item.activity_id_pk ? 'display: block;' : 'display: none;'}" class="mb-1"  class="individual-activity-form">
                                                    <div class="activity-section p-1 rounded">
                                                        <div class="row">
                                                            <div class="col-10 mt-1">      
                                                                <button class="btn btn-primary pull-left add-activity-before" style="margin-right: 10px;" data-day-id="${itineraryCardData.day_id}" data-accom-day-id="${itineraryCardData.daywise_id_pk}" data-activity-id="${item.activity_id_pk}"  data-country-id="${itineraryCardData.country_id}" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}>
                                                                    <i class="fa fa-plus mx-1"></i><span>Add Activity Before</span>
                                                                </button>
                                                            </div>
                                                            <div class="col-2 mt-1">
                                                                <!--
                                                                <a target="_blank" href="{{ url('quote/additional_activity/add/17741/167564') }}">
                                                                    <button class="btn btn-success pull-right submit_quote" title="Add Additional Activity">
                                                                        <i class="fa fa-plus mx-1"></i><span>Add Optional Activity</span>
                                                                    </button>
                                                                </a>
                                                                -->
                                                            </div>
                                                        </div>

                                                        <div class="row g-3">
                                                            <div class="col-12 mt-1">   
                                                                <p class="p-1 mb-0 day-activity-name p-1 text-center">
                                                                    ${item.activity_name ? item.activity_name : 'NA'}
                                                                </p>   
                                                            </div>
                                                            <!-- City -->
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="city">City</label>
                                                                <select name="act_city_id_fk" id="act_city_id_fk-${itineraryCardData.day_id}-${item.activity_id_pk}" data-day-id=${itineraryCardData.day_id} data-activity-id=${item.activity_id_pk} class="form-control change_activity_city" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}></select>
                                                            </div>
                                                            <!-- City Image -->
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="cityImage">City Image</label>
                                                                <select name="city_image_id_fk" id="city_image_id_fk-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}></select>
                                                            </div>
                                                            <!-- Activity -->
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="activity">Activity</label>
                                                                <select name="city_activity_id_fk" id="city_activity_id_fk-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}></select>
                                                            </div>
                                                        </div>

                                                        <div class="row g-3 mt-1">
                                                            <!-- Activity Provider -->  
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="activityProvider">Activity Provider</label>
                                                                <select name="activity_provider_id_fk" id="activity_provider_id_fk-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}></select>
                                                            </div>
                                                            <!-- Activity Timing -->
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="activityTiming">Activity Timing</label>
                                                                <div class="row g-2">
                                                                    <div class="col-6 d-flex align-items-center">
                                                                        <span>From:</span>
                                                                        <input name="act_start_time" type="time" id="act-start-time-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control mx-1" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                                    </div>
                                                                    <div class="col-6 d-flex align-items-center">
                                                                        <span>To:</span>
                                                                        <input name="act_end_time" type="time" id="act-end-time-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control mx-1" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <!-- Kilometer -->
                                                            <div class="col-lg-4 col-md-6">
                                                                <label for="kilometer">Kilometer</label>
                                                                <input type="text" name="act_kilometer" id="act-kilometer-${itineraryCardData.day_id}-${item.activity_id_pk}" class="form-control" placeholder="Enter kilometers" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''} />
                                                            </div>
                                                        </div>

                                                      
                                                    </div>
                                                </form>
                                                <!-- Activity Section End -->
                                                
                                                ${fetchActivityDropDowns(itineraryCardData.country_id, itineraryCardData.day_id, item)}
                                            `   
                                            ).join('')

                                        }    
                                        <!-- Activity Section End -->

                                        <!-- Accomodation Section Start -->
                                        <form id="update-accommodation-form-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}"  method="POST">
                                            <div class="accomodation-section p-2 mt-1 rounded">
                                                <div class="bg-success rounded accom-type-switch text-white">
                                                    <div class="row pb-1">
                                                        <div class="col-3 custom-control enxtyuepp custom-switch">
                                                            <b>Choose Accommodation Type :</b>
                                                        </div>
                                                        <div class="col-1 custom-control enxtyuepp custom-switch">
                                                            <input type="radio" name="own_accom" class="custom-control-input accom-type" data-day_id="${itineraryCardData.day_id}" data-accom_day_id="${itineraryCardData.daywise_id_pk}" id="hotelSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}" value="0" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                            <label class="custom-control-label text-white" for="hotelSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}">
                                                                <span>Hotel</span>
                                                            </label>
                                                        </div>
                                                        <div class="col-1 custom-control enxtyuepp custom-switch">
                                                            <input type="radio" name="own_accom" class="custom-control-input accom-type" data-day_id="${itineraryCardData.day_id}" data-accom_day_id="${itineraryCardData.daywise_id_pk}" id="trainSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}" value="2" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                            <label class="custom-control-label text-white" for="trainSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}">
                                                                <span>Train</span>
                                                            </label>
                                                        </div>
                                                        <div class="col-1 custom-control enxtyuepp custom-switch">
                                                            <input type="radio" name="own_accom" class="custom-control-input accom-type" data-day_id="${itineraryCardData.day_id}" data-accom_day_id="${itineraryCardData.daywise_id_pk}" id="flightSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}" value="3" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                            <label class="custom-control-label text-white" for="flightSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}">
                                                                <span>Flight</span>
                                                            </label>
                                                        </div>
                                                        <div class="col-3 custom-control enxtyuepp custom-switch">
                                                            <input type="radio" name="own_accom" class="custom-control-input accom-type" data-day_id="${itineraryCardData.day_id}" data-accom_day_id="${itineraryCardData.daywise_id_pk}" id="ownArrangementSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}" value="1" ${itineraryCardData.quote_status === 1 ? 'disabled' : ''}/>
                                                            <label class="custom-control-label text-white" for="ownArrangementSwitch-${itineraryCardData.day_id}-${itineraryCardData.daywise_id_pk}">
                                                                <span>Own Arrangement</span>
                                                            </label>
                                                        </div>
                                                    </div>
                                                </div>
                                    
                                        

                                                <!-- Update day Button END -->
                                            </div>
                                        </form>
                                        <!-- End of Accomodation Section -->
                                    </div>
                                </div>
                            </div>
                        </div>
                    `;
                    $('.daywise-act-block').append(actDayCard);

                  

                }

            } catch (error) {
                Swal.fire({
                    icon: "error",
                    title: 'Oops...',
                    text: 'AJAX' + error,
                });
            }
        } else {
            Swal.fire({
                icon: "error",
                title: 'Oops...',
                text: 'No data found.',
            });
        }
    }

this is the second function which I'm calling inside other function

  async function fetchActivityDropDowns(countryId, dayId, activityData) {

        try {

            // AJAX request to fetch activity dropdown data
            const response = await $.ajax({
                url: "{{ url('/quoteactivityplanner/getActivityDropdowns') }}",
                method: "POST",
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                },
                data: { countryId: countryId },
                dataType: "json"
            });

            // Extracting data from the response
            const { cities, cityImages, cityActivities, activityProviders, transportTypes, transportProviders, guideProviders, miscellaneous } = response.data;

            // Populating the city dropdown
            if (cities) {
                const cityDropdown = $(`#act_city_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                
                // Clear previous options and add the default option
                cityDropdown.html('<option value="">Select City</option>');
                
                // Populate the dropdown with city options
                $.each(cities, function(cId, cityName) {
                    const option = new Option(cityName, cId, false, cId == activityData.activity_city_id);
                    cityDropdown.append(option);
                });

                // Initialize or reinitialize Select2
                cityDropdown.select2({
                    placeholder: 'Select City',
                    allowClear: true,
                    width: '100%'
                }).trigger('change');

                // Listen for city selection changes
                cityDropdown.on('change', function () {
                  
                    const selectedCityId = $(this).val();
                    const selectedCityName = $(this).find(':selected').text();
                    $(`.act-accom-city-name-${dayId}`).html(`(${selectedCityName || 'No City updated'})`);

                    // Get the related activity dropdown
                    const activityDropdown         = $(`#city_activity_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                    const cityImageDropdown        = $(`#city_image_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                    const activityProviderDropdown = $(`#activity_provider_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                    const transportProviderDropdown= $(`#transport_provider_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                    const guideProviderDropdown    = $(`#guide_provider_id_fk-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`);
                    
                    if (!selectedCityId) {
                        // If no city is selected, clear and disable the activity dropdown
                        // activityDropdown.html('<option value="">Select City Activity</option>').prop('disabled', true);
                        activityDropdown.html('<option value="">Select City Activity</option>').select2().trigger('change');
                        cityImageDropdown.html('<option value="">Select City Image</option>').select2().trigger('change');
                        activityProviderDropdown.html('<option value="">Select Activity Provider</option>').select2().trigger('change');
                        transportProviderDropdown.html('<option value="">Select Transport Provider</option>').select2().trigger('change');
                        guideProviderDropdown.html('<option value="">Select Guide Provider</option>').select2().trigger('change');
                        
                    } else {
                        // If a city is selected, enable the activity dropdown and trigger the function to populate it
                        // activityDropdown.prop('disabled', false);
                        // Call your function to populate activities for the selected city
                        fetchCityActivities(selectedCityId, activityDropdown, cityImageDropdown, activityProviderDropdown, transportProviderDropdown, guideProviderDropdown);
                    }
                });
            }

           
            // Populating input fields with activity data
            $(`#description-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).text(activityData.activity_description || '');
            $(`#act-kilometer-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.act_kilometer);
            $(`#approx-drive-hour-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.approx_drive_hour);
            $(`#approx-drive-min-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.approx_drive_min);
            $(`#act-start-time-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.act_start_time);
            $(`#act-end-time-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.act_end_time);
            $(`#transport-details-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.transport_details);
            $(`#activity-notes-${dayId}-${activityData.activity_id_pk ? activityData.activity_id_pk : activityData}`).val(activityData.act_sub_description);

        } catch (error) {
            console.error('Error fetching activity dropdowns:', error);
        }
    }
Share Improve this question edited 2 days ago Inian 85.4k15 gold badges160 silver badges179 bronze badges asked 2 days ago Abhijeet KumarAbhijeet Kumar 111 silver badge8 bronze badges 3
  • Template literals aren't aware of async functions. You'd need to call the functions first, then render the template literal with the awaited data. Another alternative could be a custom tagged template literal that does know to await for awaitables. – AKX Commented 2 days ago
  • how can i do? could you explain with an example so that i can understand please. – Abhijeet Kumar Commented 2 days ago
  • 1 var x = await somePromise; var y = `${x}` – Bravo Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 0

You're trying to embed an async function inside a template literal, which is not allowed because:

  1. async functions return a Promise, and the template literal will convert the Promise to [object Promise].

  2. You cannot use await directly inside a template literal unless the value is already resolved.

    ${await (async () => { return await fetchActivityDropDowns( itineraryCardData.country_id, itineraryCardData.day_id, item ); })()}

本文标签: