javascript - How to allow the user to click on a droppable div such that the other div's dropping functionality should be disabled after clicking a droppable div -


i new jquery. presently working on project of shopping cart there 3 types of items(item1,item2,item3) , 3 bags(bag1,bag2,bag3) , 1 shopping cart such bag1 accepts item1,item2,item3 , bag2 accepts item2,item3 , bag3 accepts item3 on drop have developed far.

now want add additional functionality such user should first select(click) 1 of bag(example bag1) , try dropping items bag1 such other 2 bags dropping functionality should disable(other bags should not accept item if acceptable bag) , reverse if user selects other bag.

please try it.i need help.

http://jsfiddle.net/vwu37/15/

html

<div class="bag1" ><p>bag1</p></div> <div class="bag2" > <p>bag2</p></div> <div class="bag3" ><p>bag3</p></div> <div class="item1"><p>item1_1</p></div> <div class="item1"><p>item2_1</p></div> <div class="item1"><p>item2_1</p></div>    

js

$('.bag1').droppable({                 accept: '.item1,.item2,.item3',                  ondragenter:function(e,source){                     $(source).draggable('options').cursor='auto';                 },                 ondragleave:function(e,source){                     $(source).draggable('options').cursor='not-allowed';                 },                 ondrop:function(e,source){                     var name = $(source).find('p:eq(0)').html();                     var price = $(source).find('p:eq(1)').html();                     addproduct(name, parsefloat(price.split('$')[1]));                 }             });              $('.bag2').droppable({                 accept: '.item2,.item3',                 ondragenter:function(e,source){                     $(source).draggable('options').cursor='auto';                 },                 ondragleave:function(e,source){                     $(source).draggable('options').cursor='not-allowed';                 },                 ondrop:function(e,source){                     var name = $(source).find('p:eq(0)').html();                     var price = $(source).find('p:eq(1)').html();                    }             });              $('.bag3').droppable({                 accept: '.item3',                 ondragenter:function(e,source){                     $(source).draggable('options').cursor='auto';                 },                 ondragleave:function(e,source){                     $(source).draggable('options').cursor='not-allowed';                 },                 ondrop:function(e,source){                     var name = $(source).find('p:eq(0)').html();                     var price = $(source).find('p:eq(1)').html();                                     }             }); 

here`s simple way bag1: jsfiddle note, that, did:

$('.bag1').click(function(){
//disabling other droppables here
});

you may need remove hardcode , write more generic method disable bags. i`d suggest go through draggable , droppable jquery.ui api methods , find 1 appropriate needs. may prevent dropping right @ drop moment checking drag item , drop bag used.

update:
@ start drop bags disabled here. if click of them become enabled , droppable again.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -