Placing form dataproviders into JS variables?

Questions and answers for designing and implementing forms in Servoy

Placing form dataproviders into JS variables?

Postby sergei.sheinin » Sun Jun 08, 2014 1:31 pm

Newbie question. I have a task where I need to combine several data providers into one sentence on a form and display it in a label:

Form Datasource: table "persons"

For example the label should look as follows:

Code: Select all
<first_name> is <age> years old.


I can probably place dataproviders for <first_name> and <age>, make them hidden, bind them to form variables and use those variables to compose the label.

Is there a more straight-forward way of doing this? I wasn't able to immediately find it in docs/forums.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Placing form dataproviders into JS variables?

Postby CFDaddy » Sun Jun 08, 2014 2:03 pm

First, set 'Display Tags' property to true on your label. Next, in the text property of the label add this:

Code: Select all
%%first_name%% is %%age%% years old.


If I understood your question, that should answer it for you.

Keith
Keith L. Miller
Director of Technology
ProjecTools
4099 Hwy 36 North, Bellville, Texas 77418
P 713.371.9840 x1601 F 713.371.9841
E millerk@projectools.com W www.projectools.com
User avatar
CFDaddy
 
Posts: 75
Joined: Mon Aug 15, 2011 7:12 pm
Location: Bellville, TX USA

Re: Placing form dataproviders into JS variables?

Postby sergei.sheinin » Sun Jun 08, 2014 2:09 pm

I need to add a substring function to one field, sorry I omitted in in the original question. I thought it were possible to somehow place dataprovider into a JS variable:

Code: Select all
<first_name> is <age> years old. He said <comment.substring(1,100)>


Which would place first 100 characters of the comment. Is there a way of doing this?
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Placing form dataproviders into JS variables?

Postby mboegem » Mon Jun 09, 2014 8:10 am

The only way to use dataproviders within a text string directly on a label is the way CFDaddy showed you in his post.
There's no option to use text-functions here.

What you could do however, is create a calculation in your table and use that new calculation as dataprovider on your label.
You'll find calculations here: databases > myDb > myTable, open the table and choose the calculations tab from the editor window.

Calc should look something like this:
Code: Select all
function comment_short() {
     return comment.substring(1,100);
}


Now use 'comment_short' as a tag on your label like:
Code: Select all
%%first_name%% is %%age%% years old. He said %%comment_short%%
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1743
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Placing form dataproviders into JS variables?

Postby sergei.sheinin » Mon Jun 09, 2014 9:33 am

Not so great for a solution. :( I was hoping to be able to directly fetch dataproviders into JS variables. Will work around it by placing pre-calculated string into a database column.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Placing form dataproviders into JS variables?

Postby mboegem » Mon Jun 09, 2014 12:01 pm

sergei.sheinin wrote:Will work around it by placing pre-calculated string into a database column.


If you don't ever need this in a query, this is absolutely not the way to go.
If you want the total text in a table dataprovider though, create a calculation as I pointed out before, but this time like:
Code: Select all
function myText() {
     return first_name + " is " + age + " years old. He said " + comment.substring(1,100);
}


This way you will have an unstored dataprovider in your table.
As long as you don't use relations in your calculations, it's a great concept!
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1743
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam


Return to Forms

Who is online

Users browsing this forum: No registered users and 12 guests

cron