Pogledajte određenu poruku
Staro 20. 05. 2015.   #1
mslavko
profesionalac
Professional
 
Avatar mslavko
 
Datum učlanjenja: 25.10.2012
Poruke: 278
Hvala: 16
32 "Hvala" u 9 poruka
mslavko is on a distinguished road
Default onSelect brzi od click funcije

Kd:
Imam ovu funckciju:
function dajjson() {
    $('.auto').click(function () {
    koji = $(this).attr('data-ajdi5');
    console.log(koji);
});
$.ajax({
            url: "autoUsluge.php",
            type: "GET",
            async: true, 
            dataType: "JSON",

            success: function(data) {
            
$('.auto').autocomplete({
    
    lookup: data,
    showNoSuggestionNotice: true,
    noSuggestionNotice: '<div><a href="#" style="padding:3px; font-weight:bold;" data-toggle="modal" data-target="#myModal1"> + Dodaj novu uslugu</a></div>',
    beforeRender: function (container) {
          $('.autocomplete-suggestions').append('<div><a href="#" style="padding:3px; font-weight:bold;" data-toggle="modal" data-target="#myModal1"> + Dodaj novu uslugu</a></div>'); 
    },
    onSelect: function (suggestion) {

    
        $('#cena_'+koji).val(suggestion.cena);
        console.log(suggestion.cena);
        $('#jmere'+koji).val(suggestion.jmere);
        $('#kol'+koji).val(suggestion.kol);
        $('#popust'+koji).val(suggestion.popust);
        $('#pdv'+koji).val(suggestion.porez);
        koji =0;
    }
});
            }
});  
};
Takodje imam i html:
Kd:
<div class="col-md-12">Usluge<div class="col-md-12" style="background: #2196F3; color:#fff; height: 40px; padding-top: 10px; border-bottom: 3px solid #272D32;"><div class="col-md-6">Detalji usluge</div><div class="col-md-2">Iznos</div><div class="col-md-1">Jed.mere</div><div class="col-md-1">Količina</div><div class="col-md-1">Popust</div><div class="col-md-1">Stopa PDV</div></div><div class="col-md-12 pad" style="border-bottom: 1px dotted #ccc"><div class="row" id="128"><div class="form-group col-md-6 pad"><div class="input-group"><span class="input-group-addon"><i style="font-size: xx-large;" class="fa fa-plus text-success" onclick="newLine();"></i></span><input class="span2 form-control input-md auto bb" id="usluga" name="usluga" data-ajdi5="128" value="" type="text" autocomplete="off"></div>    </div><div class="form-group col-md-2 pad"><input id="cena_128" name="cena" type="text" placeholder="Cena" value="0" data-ajdi="128" class="form-control input-md mojborder" data-parsley-id="7355"></div><div class="form-group col-md-1 pad"><select id="jmere128" name="jmere" class="form-control mojborder" value="" data-ajdi="128"><option value="komada">kom</option> <option value="sati">h</option><option value="godina">god</option><option value="litar">l</option><option value="kg">kg</option><option value="m2">m2</option><option value="m3">m3</option><option value="km">km</option><option value="t">t</option><option value="kWh">kWh</option><option value="dan">dan</option><option value="mesec">mesec</option><option value="soba">soba</option><option value="noc">noc</option><option value="ml">ml</option><option value="pakovanje">pak</option></select><div class="parsley-errors-list" id="parsley-id-7350"></div></div><div class="form-group col-md-1 pad"><input value="0" id="kol128" name="kol" data-ajdi="128" type="text" placeholder="Količina" class="form-control input-md mojborder" data-parsley-id="8767"></div><div class="form-group col-md-1 pad"><input value="0" id="popust128" name="popust" data-ajdi="128" type="text" placeholder="Popust" class="form-control input-md mojborder" data-parsley-id="8767"></div><div class="form-group col-md-1 pad"><input value="0" id="pdv128" name="pdv" type="text" data-ajdi="128" placeholder="Stopa PDV" class="form-control input-md mojborder" data-parsley-id="8767"></div></div></div><div class="col-md-12 pad" style="border-bottom: 1px dotted #ccc"><div class="row" id="129"><div class="form-group col-md-6 pad"><div class="input-group"><span class="input-group-addon"><i style="font-size: xx-large;" class="fa fa-plus text-success" onclick="newLine();"></i></span><input class="span2 form-control input-md auto bb" id="usluga" name="usluga" data-ajdi5="129" value="" type="text" autocomplete="off"></div>    </div><div class="form-group col-md-2 pad"><input id="cena_129" name="cena" type="text" placeholder="Cena" value="0" data-ajdi="129" class="form-control input-md mojborder" data-parsley-id="7355"></div><div class="form-group col-md-1 pad"><select id="jmere129" name="jmere" class="form-control mojborder" value="" data-ajdi="129"><option value="komada">kom</option> <option value="sati">h</option><option value="godina">god</option><option value="litar">l</option><option value="kg">kg</option><option value="m2">m2</option><option value="m3">m3</option><option value="km">km</option><option value="t">t</option><option value="kWh">kWh</option><option value="dan">dan</option><option value="mesec">mesec</option><option value="soba">soba</option><option value="noc">noc</option><option value="ml">ml</option><option value="pakovanje">pak</option></select><div class="parsley-errors-list" id="parsley-id-7350"></div></div><div class="form-group col-md-1 pad"><input value="0" id="kol129" name="kol" data-ajdi="129" type="text" placeholder="Količina" class="form-control input-md mojborder" data-parsley-id="8767"></div><div class="form-group col-md-1 pad"><input value="0" id="popust129" name="popust" data-ajdi="129" type="text" placeholder="Popust" class="form-control input-md mojborder" data-parsley-id="8767"></div><div class="form-group col-md-1 pad"><input value="0" id="pdv129" name="pdv" type="text" data-ajdi="129" placeholder="Stopa PDV" class="form-control input-md mojborder" data-parsley-id="8767"></div></div></div></div>
Medjutim sada prvo polje ima klasu .auto i mogu da odaberem neku stavku sa autosuggestion, takodje kada odaberem da se pozove onSelect da updejtuje i ostale vrednosti u tom nizu. Sve je to OK.

Ali sada kada na vec odabranu vrednost kliknem (vec postoji odabir kliknem jos jednom), izmene se vrednosti (cene,jmere...) u redu iznad ili ispod (nema pravila, nisam mogao da uocim). Kako da resim taj problem?




Problem je sto je onSelect brzi od click funcije koja mi daje ID vrednost koji treba da izmenim pa tako ostaje stara vrednost. Kako da dobijem pravu vrednost ID-a pre nego sto krene onSelect.

Poslednja izmena od mslavko : 20. 05. 2015. u 13:52.
mslavko je offline   Odgovorite uz citat