Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

checkbox unselecting

$
0
0

hi I have an problem in my project. that is i'm doing checkbox functionality in project and i wrote checkbox code it's working fine and the problem is i'm creating check when json is parsing.the check boxes are creating according to the values., but when i'm selecting the boxes the id is getting fine and when i'm delselecting the checkbox it's returning unsimilar id and i worte the code like this

var adddiscounturl ="http://173.230.148.65/openbravo/org.openbravo.service.json.jsonrest/PricingDiscount" ;
  var adddiscounttableData =  [ ];
  var adddiscounttable = Ti.UI.createTableView();
  view.add(adddiscounttable);
  var adddiscountjson, response1,data, i, json2, nameLabel,row,cen;
  var adddiscountxhr = Titanium.Network.createHTTPClient({ 
         username: "DemoClient",
           password: "democlient",
     onload : function() {  
    adddiscountjson = JSON.parse(this.responseText);                
    for (var c=0,cen = adddiscountjson.response.data.length; c < cen; c++)
        {
    var adddiscountjsonfighter = adddiscountjson.response.data[c];
 
     Ti.API.info("discount" + adddiscountjsonfighter.name);
            var adddiscountrowview = Titanium.UI.createView({
                                    backgroundColor:'#ffffff',
                                        height:100,
                                    width:Ti.Platform.displayCaps.platformWidth-40      
                                    }); 
             var adddiscountviewrow = Ti.UI.createTableViewRow({
                            backgroundColor : '#fff',
                            selectedBackgroundColor : '#385292',
                            height:100,
                            data:adddiscountjsonfighter.id
                        });                                 
    //----------------check box-------------//
        var checkbox = Ti.UI.createButton({
                title: '',
               left:20,
               id:adddiscountjsonfighter.id,
               name:adddiscountjsonfighter.name,
                width: 30,
                height: 30,
                borderColor: '#A7A7A7',
                borderWidth: 2,
                borderRadius: 3,
                backgroundColor: '#EEEEE',
                backgroundImage: 'none',
                color: '#fff',
                font:{fontSize: 25, fontWeight: 'bold'},
                value: false //value is a custom property in this casehere.
        });
 
        //Attach some simple on/off actions
        checkbox.on = function() {
            this.backgroundColor = '#F18E1A';
            this.title='\u2713';
            this.value = true;
        };
 
        checkbox.off = function() {
            this.backgroundColor = '#EEEEE';
            this.title='';
            this.value = false;
        };
 
        checkbox.addEventListener('click', function(e) {
            if(false == e.source.value) {
                e.source.on();
                Ti.API.info(e.source.name);         
             adddiscountcheckidglobal = e.source.id;
             discounttableData.push(e.source.id);
             Ti.API.info(discounttableData);
            adddiscountchecknameglobal = e.source.name;
            } else {
                e.source.off();
                 //discounttableData= [ ];
                  discounttableData.splice(e.source.id,1);
                // Titanium.App.Properties.setList('ladata',data);
                Ti.API.info("sdsd"+discounttableData);
            }
        });    
    //----------------check box-------------//  
    //---------discount label-----//
                    var discountlabel = Titanium.UI.createLabel({
                            top:35,
                            text:adddiscountjsonfighter.name,
                            height:30,
                            color:'black',
                            font:{fontSize: 14, fontWeight: 'normal'},
                            width:Ti.Platform.displayCaps.platformWidth/4
                        });                                                                                                                                                                                                                                                                                                                                         
                        adddiscountviewrow.add(discountlabel);
                        adddiscountviewrow.add(checkbox);
 
                adddiscounttableData.push(adddiscountviewrow); 
 
          }
 
        //-------discount apply click-------------//          
           adddiscounttable.setData(adddiscounttableData); 
          },
         onerror:function(e){
            alert("error" + e.error);                                   
            }
         });    
 
        adddiscountxhr.open('GET',adddiscounturl);
        adddiscountxhr.send();
        //-------discount apply click-------------//

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>