Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Trusted Contributor
Posts: 100
Registered: ‎03-31-2012
My Device: Blackberry 9780
My Carrier: Telkomsel
Accepted Solution

Pass parameters to another page failed

[ Edited ]

I want to make my move pages included with the delivery of data from the previous form using pushScreen() function

 

https://github.com/blackberry/bbUI.js/wiki/Screens

 

My code like this (index.html) :

 

onscreenready: function(element, id, params) {
          if (id == 'UPDATE') {
                         UPDATE_initialLoad(element, params);
          }                                 
 }

 

My code (UPDATE.html) :

 

listItem.onclick = (function(opt) {
	return function() {

if (confirm(opt)) {
bb.pushScreen('UPDATE.html', 'UPDATE', {'data_id':id,'data_depan':depan,'data_belakang'    : belakang, 'data_phone': phone, 'data_email': email}
      );
} else {
       //Do not do anything
  } }; })(MyData+"\n\nDo you want update this data ?");

 

Once the alerts are displayed, I chose yes, but nothing happened.
I want to move from DATA.html to UPDATE.html

Can you help me what should I change in my code?

 

 

DATA.html show : HERE

 

When data click : HERE

 

I have successfully moved my page to go to, but I wanted to take the parameters are not carried

 

 

 

Update :

In UPDATE.html i have write

 

function UPDATE_initialLoad(element, params) {	
	setTimeout(UPDATE_loadAfterTimeout,100);
}

function UPDATE_loadAfterTimeout() {
	id		= data_id
	nmDepan		= data_depan
	nmBelakang	= data_belakang
	phone		= data_phone
	email		= data_email
	
	document.getElementById('txtID').value = id
	document.getElementById('txtNMDEPAN').value = nmDepan
	document.getElementById('txtNMBELAKANG').value = nmBelakang
	document.getElementById('txtPhone').value = phone
	document.getElementById('txtEmail').value = email
	
}

 Maybe there is something wrong premises used my understanding, please help me check my code

Regards,
Bertho
BlackBerry Development Advisor
Posts: 634
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: Pass parameters to another page failed

Can you show your code where you're calling the alert();?

Trusted Contributor
Posts: 100
Registered: ‎03-31-2012
My Device: Blackberry 9780
My Carrier: Telkomsel

Re: Pass parameters to another page failed

This is my code :

 

for ( var i = 0; i < response.length; ++i ) {
   id = response[i].id;
   depan = response[i].firstname;
   belakang = response[i].lastname;
   phone = response[i].phone;
   email = response[i].email;
							
				
   var Gabung,Gabung2 = ""
   Gabung	= depan+' '+belakang
   Gabung2 = "ID : "+id+"\nNama Depan : "+depan+"\nNama Belakang : "+belakang+"\nPhone : "+phone+"\nEmail : "+email

   listItem = document.createElement('div');
   listItem.setAttribute('data-bb-type', 'item');
   listItem.setAttribute('data-bb-img', 'images/icons/user.png');
   listItem.setAttribute('data-bb-title', Gabung);
   listItem.onclick = (function(opt) {
	 return function() {

if (confirm(opt)) {
bb.pushScreen('UPDATE.html', 'UPDATE', {'data_id':id,'data_depan':depan,'data_belakang': belakang, 'data_phone': phone, 'data_email': email} ); } else { //Do Nothing } }; })(Gabung2+"\n\nDo you want to update this data ?"); listItem.innerHTML = email; container = document.createElement('div'); container.appendChild(listItem); bb.imageList.apply([container]); dataList.appendChild(container.firstChild); if (bb.scroller) { bb.scroller.refresh(); } }

 

For my alert in this line :

 

if (confirm(opt)) {
bb.pushScreen('UPDATE.html', 'UPDATE', {'data_id':id,'data_depan':depan,'data_belakang': belakang, 'data_phone': phone, 'data_email': email}
	  );
   } else {
    	//Do Nothing
   }
};
})(Gabung2+"\n\nDo you want to update this data ?");

 

Regards,
Bertho
BlackBerry Development Advisor
Posts: 634
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: Pass parameters to another page failed

Sorry, I don't see what is actually triggering the popup as shown here http://s13.postimage.org/45m5ywdlj/image.png

 

I don't see any 'alert()' or 'prompt()' 

Trusted Contributor
Posts: 100
Registered: ‎03-31-2012
My Device: Blackberry 9780
My Carrier: Telkomsel

Re: Pass parameters to another page failed

I'm using JavaScript Confirm

 

Like this : http://www.tizag.com/javascriptT/javascriptconfirm.php

 

And my javascript confirm there :

 

if (confirm(opt)) {
bb.pushScreen('UPDATE.html', 'UPDATE', {'data_id':id,'data_depan':depan,'data_belakang': belakang, 'data_phone': phone, 'data_email': email}
	  );
   } else {
    	//Do Nothing
   }
};
})(Gabung2+"\n\nDo you want to update this data ?");

 My alert with data result from my server, and the contents of which are data as above

 

Gabung2 = "ID : "+id+"\nNama Depan : "+depan+"\nNama Belakang : "+belakang+"\nPhone : "+phone+"\nEmail : "+email
Regards,
Bertho
Trusted Contributor
Posts: 100
Registered: ‎03-31-2012
My Device: Blackberry 9780
My Carrier: Telkomsel

Re: Pass parameters to another page failed

If i use  onscreenready function to send parameters (page A), how i can GET this to my page ? (page B)

 

onscreenready: function(element, id, params) {
          if (id == 'UPDATE') {
                         UPDATE_initialLoad(element, params);
          }                                 
 }

 

Regards,
Bertho
BlackBerry Development Advisor
Posts: 634
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: Pass parameters to another page failed

Sorry I'm trying to follow what you're asking here.  You want to send parameters from page A, to Page B correct?

 

If so, you can do this like so:

 

bb.pushScreen('foo.htm', 'myScreenId', {'hello': 'world', 'foo': 2});

 

And your onscreenready, you would access the data with the 'params' variable like you have shown in your code.

 

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Pass parameters to another page failed

Chad has it correct... to draw the two sides of things together you will have something like the following

 

bb.pushScreen('foo.htm', 'myScreenId', {'hello': 'world', 'foo': 2});

 

Then in your bb.init() function you will declare your onscreenready and ondomready functions.  Both of these functions have a third parameter which is the object that you passed in from the bb.pushScreen() call shown above.

 

bb.init({onscreenready: function(element, id, param) {
      if (param) {
         alert(param.foo);
      }
    },

    ondomready: function(element, id, param) {
      if (param) {
         alert(param.foo);
      }
    }	
});

 

In the code above the alert should show the number 2 passed in as the property of 'foo' on the json parameter object passed into the bb.pushScreen() call.

 

The idea is that you can pass any object you like as the third parameter of the bb.pushScreen() function and it will be passed down into the onscreenready and ondomready function when that screen is about to be shown.

 

bbUI will remember that object and save it in the background screen history list, and each time that screen is loaded it will pass that object into the ready events.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Trusted Contributor
Posts: 100
Registered: ‎03-31-2012
My Device: Blackberry 9780
My Carrier: Telkomsel

Re: Pass parameters to another page failed

[ Edited ]

My question :

What is the bb.pushScreen function can't be used in when created at the time after being data is taken from the server and in the create a DIV tag?

 

My point in this section :

 

listItem = document.createElement('div');
listItem.setAttribute('data-bb-type', 'item');
listItem.setAttribute('data-bb-img', 'images/icons/user.png');
listItem.setAttribute('data-bb-title', MyData);
listItem.onclick = (function(opt) {
	return function() {
							
if (confirm(opt)) {
    //Yes Clicked
}else {
    //No Clicked
  }
};
})(Do you want to update this data ?");
listItem.innerHTML = email; container = document.createElement('div'); container.appendChild(listItem); bb.imageList.apply([container]); dataList.appendChild(container.firstChild); if (bb.scroller) { bb.scroller.refresh(); }

I'm still confused when using data transmission if my case happens if the data has been loaded onto the screen, and the user perform the action click on one of the data.

In this case, This is the case not on the index.html, but on the javascript page that requests the data to the server.
What do you do if a user click action on the screen?


I mean :

listItem.onclick = //do action

 

Here's the scenario,

1. Application load all data from my server

2. When one clicks the data in the data will be displayed to alert like the picture above.

2. If i click yes, then i want to data in the alert can be pass in my another form and set textfield value to update.

 

 

Please see the picture below :

 

 

 

See the picture below :

Regards,
Bertho
Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Pass parameters to another page failed

So are you asking "How do you store the data returned from the server in a list item to then pass to the Update Data screen?".

 

If that is the question, then I would create and object and store it on the list item.  So something like the following:

 

// Create my data structure
var data = {'title' : MyData, 
            'img': 'images/icons/user.png',
            'email': email
           };

// Create my List item           
listItem = document.createElement('div'); 
// Assign the data to the list item listItem.data = data; listItem.setAttribute('data-bb-type', 'item'); listItem.setAttribute('data-bb-img', data.img); listItem.setAttribute('data-bb-title', data.title); listItem.innerHTML = data.email; listItem.onclick = function() { if (confirm("Do you want to update this data ?")) { //Yes Clicked bb.pushScreen('updateData.htm', 'updateData', this.data); }else { //No Clicked } };

 Then in the onscreenready function I would populate the Update Data screen

 

bb.init({onscreenready: function(element, id, param) {
  if (id == 'updateData') {
      element.getElementById('myTitle').setAttribute('value') = param.title;
      element.getElementById('myEmail').setAttribute('value') = param.email;
   
      .....

  }
}
});

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter