Styling chained drop-down lists with jQuery "dd-slick" plugin interrupts automatic data refresh

I use the jquery.ddslick.min.jsjQuery plugin to create stylized drop-down boxes with images for options. I also use jquery.chained.min.jsto automatically update the data in the second selection box based on the value selected in the first drop-down list.

My requirements:

  • Styling drop-down lists to use images in options
  • Automatically update data in the second drop-down list based on the option selected in the first.
  • Run a warning displaying the value of the selected option
  • Providing Scrolling Dropdowns

Currently, items are not updated in the second select box when I select an option in the first. I am also having problems triggering an alert when selecting an option; scroll functionality also does not work properly.

HTML:

<select id="inames">
    <option value="">-slect place-</option>
    <option value="Utilities">Utilities</option>
    <option value="Emergency Services">Emergency Services</option>
    <option value="General">General</option>
</select> 

<select id="ddslicks" >
    <option data-imagesrc="../css/PoiImages/airport.png" class="Utilities" value="airport"></option>
    <option data-imagesrc="../css/PoiImages/ambulance.png" class="Utilities" value="ambulance"></option>
    <option data-imagesrc="../css/PoiImages/atm.png" class="General" value="atm"></option>
    <!-- _  _  etc -->
</select>

JavaScript:

$("#ddslicks").chainedTo("#inames"); /* or $("#series").chainedTo("#mark"); */

I am also having trouble adding a warning.

alert($('#ddslicks').val())
+4
source share
1 answer

You can accept it or leave it, but here is an alternative solution. It does not use the chain, but I believe that it performs the same functions only with ddslick ( http://jsfiddle.net/lkritchey/Uw9kL/2/ ).

JSON ( -). ddslick ( , ). , , ( ).

var categoryData = [{
    text: "Utilities",
    value: 1,
    selected: false,
    description: "Utilities"
}, {
    text: "Emergency Services",
    value: 2,
    selected: false,
    description: "Emergency Services"
}, {
    text: "General",
    value: 3,
    selected: false,
    description: "General"
}];

var utilitiesData = [{
    text: "Airport",
    value: 1,
    selected: false,
    description: "Airport",
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
}];

var generalData = [{
    text: "Mall",
    value: 11,
    selected: false,
    description: "Mall",
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
}, {
    text: "Shopping Plaza",
    value: 12,
    selected: false,
    description: "Shopping Plaza",
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png"
}];

:

$('#inames').ddslick({
    data: categoryData,
    width: 300,
    imagePosition: "left",
    selectText: "Select a place",
    onSelected: function (data) {
        updateDropDown(data.selectedData.value);
    }
});
$("#ddslicks").ddslick({width: 300,
        imagePosition: "left",
                        selectText: "Select"});

function updateDropDown(value) {
    var newData;
    if (value == 1) {
        newData = utilitiesData;
    } else {
        newData = generalData;
    }
    $('#ddslicks').ddslick("destroy");
    $("#ddslicks").empty();
    $("#ddslicks").ddslick({
        data: newData,
        width: 300,
        imagePosition: "left",
        selectText: "Select"
    });
}

, update - - , chained.js? , .

( ):

" " ( )

JavaScript , "" HTML. , , , , . ddslick.

:

    <div id="inames" class="dd-container" style="width: 300px;">
    <div class="dd-select" style="width: 300px; background: none repeat scroll 0% 0% rgb(238, 238, 238);">
        <input class="dd-selected-value" type="hidden"> <a class="dd-selected">Select a place</a>
 <span class="dd-pointer dd-pointer-down"></span> 
    </div>
    <ul class="dd-options dd-click-off-close" style="width: 300px;">
        <li> <a class="dd-option">
                <input class="dd-option-value" type="hidden" value="1">
                <label class="dd-option-text">Utilities</label > 
                <small class = "dd-option-description dd-desc"> Utilities</small>
            </a> 
        </li>
        <li> <a class="dd-option">
                <input class="dd-option-value" type="hidden" value="2">
                <label class="dd-option-text">Emergency Services</label > 
                    <small class = "dd-option-description dd-desc" > Emergency Services </small>
            </a> 
        </li>
        <li>
<a class="dd-option">
<input class="dd-option-value" type="hidden" value="3">
    <label class="dd-option-text">General</label > < small class = "dd-option-description dd-desc" > General </mall>
</a> 
        </li>
    </ul>
</div>
<div id="ddslicks" class="dd-container" style="width: 300px;">
    <div class="dd-select" style="width: 300px; background: none repeat scroll 0% 0% rgb(238, 238, 238);">
        <input class="dd-selected-value" type="hidden">
<a class="dd-selected">Select</a > <span class = "dd-pointer dd-pointer-down" > </span>

    </div>
    <ul class="dd-options dd-click-off-close" style="width: 300px;"></ul>
</div>

, , . "select" div ( ), .

, " ", dd-options. , ? CSS. , , CSS .

.dd-options {
    max-height: 200px;
}

max-height , . , !

:

http://jsfiddle.net/lkritchey/Uw9kL/11/

+5

Source: https://habr.com/ru/post/1540845/


All Articles