fields that retain across forms?

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

fields that retain across forms?

#1

Postby t4nu » Sat Mar 05, 2016 8:39 am

Hi,
is it possible to have fields which values can exists across forms within a project?
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

#2

Postby Steve James » Sat Mar 05, 2016 9:34 am

No I don't believe you can but you can pass the value of a field in form A into form B either via url parameter or callForm

See
http://dev-docs.verj.io/ufs/doc/javadoc ... bForm.html and look at the callForm options.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#3

Postby t4nu » Sat Mar 05, 2016 10:02 am

Yes, I am aware of that method. Just think it rather bothersome if the field needed more than 2.
Steve James wrote:No I don't believe you can but you can pass the value of a field in form A into form B either via url parameter or callForm

See
http://dev-docs.verj.io/ufs/doc/javadoc ... bForm.html and look at the callForm options.
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

#4

Postby Steve James » Sat Mar 05, 2016 3:14 pm

How about create a KVP object and pass that as a single object into the new form, then populate each KVP into the appropriate field.

Build the field object as you want eg all fields, or just push the fields you want.

Code: Select all

var ary = [];
for (var field in Iterator(fields.iterator()) )
{
    var thisValue = {'name':field.elementName,'value':field.value};
    ary.push(thisValue);
}
You've now got an object with all the field names/values you want. You could pass this as a single url parameter if it isn't too big; I encrypt the object then decrypt it in form2 (see http://forum.ebasetech.com/forum/viewtopic.php?t=1044), otherwise turn it into a cookie or session variable.

If form 2 is intended for a different session then maybe insert it into a db table and pass an id as the url parameter for retrieval.

In form 2 just retrieve the object and loop through it to populate the fields.

Code: Select all

ary.forEach(function(f){
	fields.getField(f.name).setValue(f.value);
	})
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#5

Postby t4nu » Sun Mar 06, 2016 12:18 am

Thank you for the idea.
Seems interesting. Will try to figure it out.
Once again thank you. :D
Steve James wrote:How about create a KVP object and pass that as a single object into the new form, then populate each KVP into the appropriate field.

Build the field object as you want eg all fields, or just push the fields you want.

Code: Select all

var ary = [];
for (var field in Iterator(fields.iterator()) )
{
    var thisValue = {'name':field.elementName,'value':field.value};
    ary.push(thisValue);
}
You've now got an object with all the field names/values you want. You could pass this as a single url parameter if it isn't too big; I encrypt the object then decrypt it in form2 (see http://forum.ebasetech.com/forum/viewtopic.php?t=1044), otherwise turn it into a cookie or session variable.

If form 2 is intended for a different session then maybe insert it into a db table and pass an id as the url parameter for retrieval.

In form 2 just retrieve the object and loop through it to populate the fields.

Code: Select all

ary.forEach(function(f){
	fields.getField(f.name).setValue(f.value);
	})
0 x

Dave
Ebase Staff
Posts: 89
Joined: Mon Sep 10, 2007 11:48 am

#6

Postby Dave » Fri Mar 11, 2016 2:48 pm

Easiest thing is to use a form session object - that's what they're for. Just put whatever shared state you need into an object and pin it in form session state, e.g.

Code: Select all

// function to define an object to hold state
function setUpStateObject() {
   var s = function() {
	            var orgID;
	            this.getOrgID = function() {return orgID;}
	            this.setOrgID = function(id) {orgID = id;}
	        }        
   if (client.formSession.getFormSessionAttribute('state') == null) {
      // create a new object
      client.formSession.setFormSessionAttribute('state', new s());      
   }
}
and then use it like this from any form:

Code: Select all

client.formSession.getFormSessionAttribute('state').getOrgID();
or

Code: Select all

client.formSession.getFormSessionAttribute('state').setOrgID(someValue);
If you want to share state between any form running in your browser session (like in different browser tabs or in pop-up windows) use HTTP session state instead. Or, if you want everyone using your app to be able to share the state use Servlet Context instead. See client.httpSession and client.getHttpSession().getServletContext() for reference.

Dave
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#7

Postby t4nu » Sat Mar 12, 2016 2:10 pm

Thank you very much for a detail explaination.
Really appreciate it.
Dave wrote:Easiest thing is to use a form session object - that's what they're for. Just put whatever shared state you need into an object and pin it in form session state, e.g.

Code: Select all

// function to define an object to hold state
function setUpStateObject() {
   var s = function() {
	            var orgID;
	            this.getOrgID = function() {return orgID;}
	            this.setOrgID = function(id) {orgID = id;}
	        }        
   if (client.formSession.getFormSessionAttribute('state') == null) {
      // create a new object
      client.formSession.setFormSessionAttribute('state', new s());      
   }
}
and then use it like this from any form:

Code: Select all

client.formSession.getFormSessionAttribute('state').getOrgID();
or

Code: Select all

client.formSession.getFormSessionAttribute('state').setOrgID(someValue);
If you want to share state between any form running in your browser session (like in different browser tabs or in pop-up windows) use HTTP session state instead. Or, if you want everyone using your app to be able to share the state use Servlet Context instead. See client.httpSession and client.getHttpSession().getServletContext() for reference.

Dave
0 x


Who is online

Users browsing this forum: No registered users and 21 guests