Dynamic Checkboxes

I would like to show the user a list of records from table and allow the user to select which records to include with a new record in a new database.

I will create a new record for each item checked in the list. I have included a quick sample of an html style form that I would like to do in Servoy…

==============================================
var my_html = “”;
my_html = my_html + “”;

my_html = my_html + “”;
my_html = my_html + “Form Name”;
my_html = my_html + “Form Description”;
my_html = my_html + “Include This Form”;
my_html = my_html + “”

for ( var i = 1 ; i <= controller.getMaxRecordIndex() ; i++ )
{
controller.setSelectedIndex(i);
my_html = my_html + “”;
my_html = my_html + “” + template_name + “”;
my_html = my_html + “” + description + “”;
my_html = my_html + "<input type=checkbox “;
my_html = my_html + “name=template_” + i + " value=ON>”;
my_html = my_html + “”;

}

my_html = my_html + “”;

controller.setDataProviderValue(‘globals.my_html’,my_html);

I want to grab the user inputs and save the record in a new table by spliting the submitted values. Any thoughts greatly appreciated.

Hi darthtall,

First of all welcome to the forum. I see it’s your first post.

Your approach won’t work since the HTML will be rendered in memory and any changes to the values too.
What you can do is to use a dynamic value list attached to a checkbox field.
Only downside is that you can’t have a custom value list per record in a list/table view.
Another option would be to use the HTML to only show the values in an non-editable field and using a edit dialog to edit this field using a custom value list.

Hope this helps.

Thanks Rob.

I had hope to create dynamic check boxes based on a list view. To bad you can not submit the html to a form. I can do this in .net with a great deal of code. Had hope that I could create dynamic check boxes to store the choices later… Looks like I may have to rethink my approach

Hi darthtall,

darthtall:
I had hope to create dynamic check boxes based on a list view. To bad you can not submit the html to a form. I can do this in .net with a great deal of code. Had hope that I could create dynamic check boxes to store the choices later… Looks like I may have to rethink my approach

Well you could do it with little less code but still a workaround nevertheless.
Use a headless client/Webclient and load that in a HTML area of the Rich client. But there are a few downsides on this approach like the use of extra client licenses. Or you can use a headless client and bind that to the application, therefore only using 1 license for all users. But it won’t be multithreading and use of globals and such is not recommend then.
Of course you could use another technology to serve the HTML but then you won’t have the data broadcasting of the changes to other clients.

Hope this helps.

==============
Form in asp

<% Set Conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.Recordset") Conn.Open "DSN=Thing;" strSQL = "SELECT * FROM things" rs.Open strSQL, Conn %>

Package Name

Package Desc

<%
a=1
do until rs.EOF
desc = rs(“description”)
id = rs(“Template_ID”)
name = rs(“template_name”)
%>


<%
a = a + 1
rs.MoveNext
%>

<% loop rs.close Conn.close set rs = nothing set conn = nothing %>
Form Name Form Desc Include?
<%=name%> <%=desc%>

=========== END FORM

======================
Form Processing page

<%
package_name = request.form(“package_name”)
package_desc = request.form(“package_desc”)

my_var = request.form(“template”)

my_var2 = split(my_var,“|”)

Max = Ubound(my_var2)-1

For i = 0 to Max

'For i = 0 to Ubound(my_var2)

my_var3 = my_var2(i)

my_test = InStr(my_var3,“ON”)

if my_test > 0 then
my_var4 = split(my_var3,“,”)

for a = 0 to Ubound(my_var4)

if Len(my_var4(a)) > 0 then

if i = 0 then
if a = 1 then

my_sql = “”
my_sql = my_sql & “UPDATE pdf_package_template_instance SET pdf_package_template_instance.pti_name='” & package_name & “',”
my_sql = my_sql & “pdf_package_template_instance.pti_desc='” & package_desc & “',”
my_sql = my_sql & “pdf_package_template_instance.template_id=” & my_var4(a) & “;”
response.write my_sql & "
"
my_sql = “”
end if
else
if a = 2 then

my_sql = “”
my_sql = my_sql & “UPDATE pdf_package_template_instance SET pdf_package_template_instance.pti_name='” & package_name & “',”
my_sql = my_sql & “pdf_package_template_instance.pti_desc='” & package_desc & “',”
my_sql = my_sql & “pdf_package_template_instance.template_id=” & Trim(my_var4(a)) & “;”
response.write my_sql & "
"
my_sql = “”
end if
end if
end if

next

end if

next

%>

=============

END PROCESS

-===================

now to do this in servoy…

with a bean for the selection list maybe and then process the selections on a button any help greatly appreciated.

Coming from .net world no Java prog exp at all… so be gentle

As Robert suggested the most easy way to get this done is:

  1. create custom valuelist (leave empty)
  2. attach valuelist to field with displaytype “check”
    2a) attach global variable as dataprovider
  3. via scripting fill the valuelist with application.setValuelistItems(…) see sample how to use this
  4. make a separate button method to process the selected actions while reading the global

Hello,
I am facing the same problem and I followed your steps that are written above, but I couldn’t continue with step 4 (make a separate button method to process the selected actions while reading the global) because even if they are checkboxes, i can only select 1 value. Or did I get it wrong? I am using Servoy 3.5.7. Thanks in advance.

DB

diana.bodnarescu:
i can only select 1 value

To be able to select multiple values, you underlaying dataprovider must be of type text

Thank you for your answer!
It works if the dataprovider (a global variable) is text. Could you please tell me if there is a way to preselect the checkboxes?

D.B.

Hi Diana,

Your question is answered in viewtopic.php?t=11706 .
Please post a question only in 1 thread.

This is exactly the problem I’ve been working on solving with the solutionModel this week. I’m not all the way there yet, but the new 4.1 feature to base a form on a dataset works nicely for this type of thing.

	var q = "SELECT resource_id, resource_name, 0 AS 'is_selected' FROM resources \
				WHERE is_active = 1 ORDER BY resource_name asc";
	var ds = databaseManager.getDataSetByQuery('cfbs',q,[],-1);
	var fds = ds.createDataSource('resource_select_data',[DM_COLUMNTYPE.INTEGER,DM_COLUMNTYPE.TEXT,DM_COLUMNTYPE.INTEGER]);

	var frmName = 'resource_select_dialog';
	solutionModel.removeForm(frmName);
	var frm = solutionModel.newForm('resource_select_dialog',fds,'cfbs_main',false,250,250);

	frm.scrollbars = SM_SCROLLBAR.HORIZONTAL_SCROLLBAR_NEVER;
	frm.view = SM_VIEW.LOCKED_TABLE_VIEW;
	
	var lbl = frm.newLabel('temp',20,30,100,23);
	lbl.dataProviderID = 'resource_name';
	lbl.anchors = SM_ANCHOR.ALL;
	
	var chk = frm.newCheck('is_selected',20,40,23,23);

I’ve then built a form with the a dynamic dataset with a column for the checkbox that is not in the database. If I show the form, I can check the boxes for the lines I want – then I will have to parse out the items checked.

I’m still in-process on this, but it seems to be working out nicely.

greg.