reseting checkbox on reset button click in titanium - titanium

i googled and found below code which creats checkbox .but these check boxes get selected when i click both the checkbox.my requirement is, i need one check box is checked while other is unchecked.that is one checkbox has to be checked at a time .and pressing reset button all the check box should be unchecked.
var win = Ti.UI.createWindow({backgroundColor:"white"});
var checkbox = Ti.UI.createSwitch({
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
title:"male",
value:true
});
win.add(checkbox);
checkbox.addEventListener("change", function(e){
Ti.API.info("The checkbox has been set to " + e.value);
});
var checkbox1 = Ti.UI.createSwitch({
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
title:"female",
value:true
});
win.add(checkbox1);
checkbox1.addEventListener("change", function(e){
Ti.API.info("The checkbox has been set to " + e.value);
});
var resetbtn = Ti.UI.createButton({
top : '100',
width : '50',
height : '35',
title : 'Reset'
});
win1.add(resetbtn);
resetbtn.addEventListener('click', function(){
checkbox.value='';
}
win.open();
please help me i am new to titanium,i want checkbox should be unclicked on presing resetbutton press and one checkbox as to get clicked at a time.

As your query you want the following thing :
You need one check box is checked while other is unchecked i'e,
one checkbox has to be checked at a time.
Pressing reset button all the check box should be unchecked.
For Point 1 : Here is the code for this point :
var win = Ti.UI.createWindow({backgroundColor:"white"});
var checkbox = Ti.UI.createSwitch({
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
title:"male",
value:true,
width: "200dp", height:"120dp", left:"10dp"
});
win.add(checkbox);
checkbox.addEventListener("change", function(e){
Ti.API.info("The checkbox has been set to " + e.value);
if(e.value) {
checkbox1.value=false;
} else {
checkbox1.value=true;
}
});
var checkbox1 = Ti.UI.createSwitch({
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
title:"female",
value:true
});
win.add(checkbox1);
checkbox1.addEventListener("change", function(e){
Ti.API.info("The checkbox has been set to " + e.value);
if(e.value) {
checkbox.value=false;
} else {
checkbox.value=true;
}
});
var resetbtn = Ti.UI.createButton({
top : '100',
width : '50',
height : '35',
title : 'Reset'
});
win.add(resetbtn);
resetbtn.addEventListener('click', function(){
Ti.API.info('Refresh button click');
});
win.open();
For point 2 : I am just code as per your need but this not the right way i think. If you want to reset checkbox with your requirement (one checkbox has to be checked at a time) then better to use image for checkbox or radio-button. But Here is the code for that :
var win = Ti.UI.createWindow({backgroundColor:"white"});
var checkFlag = true;
var resetTouch = false;
var checkbox = Ti.UI.createSwitch({
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
title:"male",
value:true,
width: "200dp", height:"120dp", left:"10dp"
});
win.add(checkbox);
checkbox.addEventListener("change", function(e){
Ti.API.info("The checkbox has been set to " + e.value);
if(e.value) {
checkbox1.value=false;
} else {
checkbox1.value=true;
}
});
var checkbox1 = Ti.UI.createSwitch({
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
title:"female",
value:true
});
win.add(checkbox1);
checkbox1.addEventListener("change", function(e){
Ti.API.info("The checkbox has been set to " + e.value);
if(e.value) {
checkbox.value=false;
} else {
checkbox.value=true;
}
});
var resetbtn = Ti.UI.createButton({
top : '100',
width : '50',
height : '35',
title : 'Reset'
});
win.add(resetbtn);
var checkboxNew = Ti.UI.createSwitch({
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
title:"male",
value:false,
width: "200dp", height:"120dp", left:"10dp"
});
win.add(checkboxNew);
var checkboxNew1 = Ti.UI.createSwitch({
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
title:"female",
value:false
});
win.add(checkboxNew1);
resetbtn.addEventListener('click', function(){
Ti.API.info('checkFlag = ' + checkFlag);
if(checkFlag) {
checkbox.hide();
checkbox1.hide();
checkboxNew.show();
checkboxNew1.show();
checkFlag = false;
} else {
checkbox.show();
checkbox1.show();
checkboxNew.hide();
checkboxNew1.hide();
checkFlag = true;
}
});
checkboxNew.addEventListener("change", function(e){
Ti.API.info("The checkboxNew has been set to " + e.value);
checkboxNew.value=false;
checkboxNew1.value=false;
});
checkboxNew1.addEventListener("change", function(e){
Ti.API.info("The checkboxNew1 has been set to " + e.value);
checkboxNew.value=false;
checkboxNew1.value=false;
});
checkbox.hide();
checkbox1.hide();
checkboxNew.show();
checkboxNew1.show();
win.open();
Please Take a look on it.

Related

Remain data that input in text field

My case is that I want to remain/save entered data on text field and will make a drop down list of my previous entered data when I click on the text field and also if i close and open back the application, the entered data will still be in the drop down list. Example, i entered "abc123" in the text field and i press enter on a button, it will save "abc123" in the drop down list of the text field and if i quit the application and enter again, "abc123" will still be in the drop down list.
var win = Ti.UI.createWindow({
backgroundColor: 'white',
});
var txtfield = Ti.UI.createTextField({
});
var btn = Ti.UI.createButton({
title: 'go'
});
win.add(btn);
win.add(txtfield);
win.open();
You'll need to save the values to SQLite or Ti.App.Properties.
Here is a working example :
var win = Ti.UI.createWindow({
backgroundColor : 'white',
layout : 'vertical'
});
var txtfield = Ti.UI.createTextField({
width : Ti.UI.FILL,
height : Ti.UI.SIZE,
hintText : 'Enter new values...',
top : 0
});
var picker = Ti.UI.createPicker({
top : 10
});
var data = (Ti.App.Properties.hasProperty('itemList')) ? Ti.App.Properties.getList('itemList') : [];
Ti.API.info('data is ' + data);
var m = [];
if (data)
data.forEach(function(item) {
m.push(Ti.UI.createPickerRow({title:item}));
});
Ti.API.info('M is ' + m);
if (m.length > 0)
picker.add(m);
var btn = Ti.UI.createButton({
top : 10,
width : Ti.UI.SIZE,
height : Ti.UI.SIZE,
title : 'go'
});
btn.addEventListener('click', function(e) {
var s = [];
if (Ti.App.Properties.hasProperty('itemList')) {
Ti.API.info('Property found');
s = Ti.App.Properties.getList('itemList');
}
Ti.API.info('S is ' + s);
s.push(txtfield.value);
Ti.App.Properties.setList('itemList', s);
picker.add(Ti.UI.createPickerRow({title:txtfield.value}));
txtfield.value = '';
});
win.add(btn);
win.add(txtfield);
win.add(picker);
win.open();
Definitely recommend to use sessionStorage or localStorage

Opening a new window on a tableview row click in titanium

I am trying to open a new window by click a row in tableview in titanium.
this is my code,
function listpage(){
var tabgroup=Ti.UI.createTabGroup();
var win = Ti.UI.createWindow({
title:'Listpage',
backgroundColor:'#fff'
});
var dataArray = [{
title:'Sunday',
hasChild:true,
test:'detail'}];
for(var i=0;i<dataArray.length;i++){
dataArray[i].color = '#000';
dataArray[i].font = {fontWeight:'bold',fontSize:20};
}
var tableview=Ti.UI.createTableView({
data:dataArray
});
tableview.addEventListener('click',function(e){
if(e.rowData){
Ti.API.info(e.rowData.title);
var winEvent = Titanium.UI.createWindow({
backgroundColor:'#fff',
url:e.rowData.test
});
winEvent.open({animation:true});
}
});
win.add(tableview);
win.open();
}
detail.js code :
var self = Ti.UI.createWindow({
title:'Detail',
color:'#000',
backgroundColor:'white'
});
var label = Ti.UI.createLabel({
text:'Hai',
color:'#000'
});
self.add(label);
What to do to open detail.js window by clicking tableview row.
Thankyou.
Surendra, this is something similar to your problem. It opens a window while you clicks on each row.
Code is
var wndHome = Ti.UI.createWindow({
backgroundColor : 'white'
});
var tableView = Ti.UI.createTableView({
top : 0
});
var tabledata = [];
for(var i = 0 ; i < 10; i++){
var row = Ti.UI.createTableViewRow({
title : 'Title of window',
url : 'details.js'
});
tabledata.push(row);
}
tableView.data = tabledata;
wndHome.add(tableView);
wndHome.open();
tableView.addEventListener('click', function(e){
var wndNewWindow = Ti.UI.createWindow({
backgroundColor : '#999966',
url : e.rowData.url
});
wndNewWindow.open();
});
details.js file
var self = Ti.UI.currentWindow;
var label = Ti.UI.createLabel({
text:'Hai',
color:'#000'
});
self.add(label);
Here I've given the url to details.js. If you want to use different windows, then keep the file names in an array and while creating the tableViewRow, you can simply add the array element as the url(eg: fileArray = ['file1.js', 'file2.js','file3.js'];).
Try this and change your code as per your requirement.

Not updating list in the panel at the run time in sencha

i have two panel. when i'm click on the left panel items its calling web service and populating the right panel and same time its updating the number of items in the right panel to the left panel item which is clicked.
for first time its updating the left panel items but when i click on the other left panel item its not updating left panel items again.
its updating only first time.
my code is:
onInboxListTap:function (dataview, index, item, record) {
console.log('Inside onInboxListTap function');
var queuestore = dataview.getStore();
var rec = queuestore.getAt(index);
console.log(rec.data.workSetName);
var store = Ext.getStore('InboxWorkitemStore');
store.clearData(); //Function To clear WorkitemStore
//creating object of InboxQueueServices class
var inboxQueueServiceObject =
Ext.create('InfoImage.common.services.InboxQueueServices', {
config:{
scope:this
}
}, this.onQueueContentRetrievalSuccess, this.onQueueContentRetrievalFailure());
// calling loadQueueContent function to load queue contents
inboxQueueServiceObject.loadQueueContent(rec.data.workSetName);
},
//To call Function onQueueContentRetrievalSuccess after loadQueueContent successful
onQueueContentRetrievalSuccess:function () {
console.log('Inside onQueueContent Retrieval Success function');
var store = Ext.getStore('InboxWorkitemStore');
//Getting componenet queueDetails list
var inboxWorkitemList = Ext.getCmp('inboxWorkitemList');
var queueDetails = Ext.getCmp('queueDetails');
var queueList = Ext.getCmp('queuelist'); //Getting component list
var queueViewPanel = Ext.getCmp('queueViewPanel'); //Getting queueViewPanel
queueDetails.setStore(store);
store.sync();
var queueCount = store.getCount();
if (queueCount > 0) {
var queueItem = store.getAt(0);
var queueStore = queueList.getStore();
queueStore.each(function (record) {
if (record.get('workSetName') == queueItem.get('sourceWorkstep')) {
record.data.queueName = queueItem.get('sourceWorkstep') + '(' +
queueCount + ')';
}
});
queueList.setStore(queueStore);
queueStore.sync();
queueList.getStore().each(function (record) {
console.log('queueList:' + record.data.queueName);
});
console.log('store UPDATED');
}
queueList.refresh();
console.log('store count: ' + store.getCount());
console.log(queueDetails);
// navigates the panel
queueViewPanel.animateActiveItem(
inboxWorkitemList, {
type:'slide',
direction:'up',
duration:250
});
},
Please help me on this isssue.
i have to set record for that i resolve it.
queueStore.each(function (record) {
if (record.get('workSetName') == workitem.get('sourceWorkset')) {
record.data.queueName = workitem.get('sourceWorkset')
+ '(' + queueCount + ')';
// queueStore.updateRecord(record.data.queueName);
record.set(record.data.queueName);
}
});

After Refresh dont append the same data

im using for first time appcelerator for a Iphone app, im using a TableViewRow, when the window load all is fine, but if i want to refresh the window, the TableViewRow repeat the same data every time that i push refresh, so, i have 5 Categories, after refresh im having the same Categories repeting every time that im trying to refresh.
Ti.UI.backgroundColor = '#dddddd';
var url = "http://remoteJSON.js";
var win = Titanium.UI.currentWindow;
var table = Titanium.UI.createTableView();
var tableData = [];
var json, categorias, categoria, i, row, categoriaLabel, descripcionLabel;
var refreshBtn = Titanium.UI.createButton({
systemButton: Ti.UI.iPhone.SystemButton.REFRESH
});
refreshBtn.addEventListener('click', function() {
loadTutoriales();
});
win.setRightNavButton(refreshBtn);
var actInd = Titanium.UI.createActivityIndicator({
bottom:10,
height:50,
width:10,
style:Titanium.UI.iPhone.ActivityIndicatorStyle.PLAIN
});
function loadTutoriales(){
if(!Titanium.Network.online){
alert("Debe conectarse a internet.");
}
var xhr = Ti.Network.createHTTPClient({
onload: function() {
actInd.show();
actInd.message = 'Loading...';
//Ti.API.debug(this.responseText);
json = JSON.parse(this.responseText);
for (i = 0; i < json.categorias.length; i++) {
var rowColor = '#eeeeee';
if(i & 1){
rowColor = '#ffffff';
}
categoria = json.categorias[i];
var row = Ti.UI.createTableViewRow({
height:'auto',
hasChild:true
});
row.backgroundColor=rowColor;
/* add */
var post_view = Titanium.UI.createView({
height:'auto',
layout:'vertical',
top:5,
right:5,
bottom:5,
left:5
});
var av_image = Titanium.UI.createImageView({
image:categoria.imageUrl,
top:0,
left:0,
height:48,
width:48
});
post_view.add(av_image);
var inner_view = Titanium.UI.createView({
height:'auto',
layout:'vertical',
top:0,
right:0,
bottom:0,
left:0
});
/* end add */
var categoriaLabel = Ti.UI.createLabel({
text:categoria.categoryName,
left:54,
width:120,
top:-48,
bottom:0,
height:18,
textAlign:'left',
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:14,fontWeight:'bold'}
});
inner_view.add(categoriaLabel);
var descripcionLabel = Ti.UI.createLabel({
text:'"' + categoria.description + '"',
left:54,
top:0,
bottom:2,
height:'auto',
width:'auto',
textAlign:'left',
font:{fontSize:14}
});
inner_view.add(descripcionLabel);
post_view.add(inner_view);
row.add(post_view);
//row.add(descripcionLabel);
tableData.push(row);
}
table.setData(tableData);
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT: " + this.responseText);
Ti.API.debug("ERROR: " + e.error);
alert('There was an error retrieving the remote data. Try again.');
},
timeout:5000
});
//win.add(actInd);
win.add(table);
win.open();
//actInd.hide();
xhr.open("GET", url);
xhr.send();
}
loadTutoriales();
When you press the refresh button clear the tableData array and assign to table set data function before you fill your table again. So it will empty your table first and than fill new refreshed data.
Like this,
refreshBtn.addEventListener('click', function() {
tableData = [];
table.setData(tableData);
loadTutoriales();
});

Page refresh with onclick event in dojo and I don't want a page refresh

For some reason in IE8 when I run this function after an onclick event it causes a page refresh. I don't wan the page refresh to happen.
var edealsButton = dojo.byId("edeals_button");
var edealEmailInput = dojo.byId("edeals_email");
var edealsSignup = dojo.byId("edeals_signup");
var edealsThankYou = dojo.byId("edeals_thankyou");
var currentValue = dojo.attr(edealEmailInput, 'value');
if (currentValue != '' && currentValue != 'Enter your email') {
var anim = dojox.fx.flip({
node: edealsSignup,
dir: "right",
duration: 300
})
dojo.connect(anim, "onEnd", this, function() {
edealsSignup.style.display = "none";
edealsThankYou.style.display = "block";
})
dojo.connect(anim, "onBegin", this, function() {
var criteria = { "emailAddress": '"' + currentValue + '"' };
alert("currentValue " + currentValue);
var d = essentials.CallWebserviceMethod('AlmondForms.asmx/SignupEdeal', criteria);
d.addCallback(function(response) {
var obj = dojo.fromJson(response);
alert(obj.d);
if (obj != null && obj.d != null) {
//alert(obj.d);
if (obj.d == false)
{
var edealSuccess = dojo.byId("edeals_succes_thankyou");
var edealError = dojo.byId("edeals_error_thankyou");
alert("edealError: " + edealError);
dojo.style(edealSuccess, "display", "none");
dojo.style(edealError, "display", "inline-block");
}
else
{
var edealSuccess = dojo.byId("edeals_succes_thankyou");
var edealError = dojo.byId("edeals_error_thankyou");
dojo.style(edealSuccess, "display","inline-block");
dojo.style(edealError, "display", "none");
}
}
else {
var edealSuccess = dojo.byId("edeals_succes_thankyou");
var edealError = dojo.byId("edeals_error_thankyou");
dojo.style(edealSuccess, "display", "none");
dojo.style(edealError, "display", "inline-block");
}
});
})
anim.play();
edealEmailInput.innerHTML == 'Enter your email';
}
else
{
dojo.attr(edealEmailInput, 'value', 'Enter your email');
dojo.style(edealEmailInput, 'color', '#CC2525');
}
It looks like your "d.addCallback" code might not be disposed of properly. You might want to try placing "dojo.stopEvent()" possibly before the "anim.play();" line and see if this would stop the postback.
From the api.dojotoolkit.org site, the dojo.stopEvent() "prevents propagation and clobbers the default action of the passed event". From the docs.dojocampus.org site, they say that "dojo.stopEvent(event) will prevent both default behavior any any propagation (bubbling) of an event."
Good luck, and hope this helps you out some.