checkbox on list form

99 views
Skip to first unread message

Edu Reyes Jr

unread,
Aug 27, 2021, 11:39:07 AM8/27/21
to Lightning - 4D Web Applications
Hi all!

I have a boolean field that I want to display in the list page. I made it as far as putting in checkboxes and the value beside it.
Voucher_list_cb.png

I'm having problems displaying the checkbox as checked when the value is true, same goes for false.

I am thinking of modifying the html on the script part but I don't know how to write it.
Something like, - if data is true, then <input type="checkbox" ... checked>, 
else <input type="checkbox"  ... > -
Voucher_list_cb_code.png

Or maybe it can be controlled on 4D side, but I don't know how to do that either. 

Has anyone tried to do the same?

TIA

-Edu

Graham Langley

unread,
Aug 28, 2021, 6:17:05 AM8/28/21
to Lightning - 4D Web Applications
There are a number of ways to implement checkboxes in the table;

JavaScript

{
                    targets: [ 5 ], // assigned
                    render: function ( data, type, row, meta ) {
                        if(type === 'display'){
                       
                            if(data == 'true')  {
                           
                            data = '<input type="checkbox" disabled="disabled" checked="checked" />';
                           
                        }   else    {
   
                            data = '<input type="checkbox" disabled="disabled"/>';
                        }
                       
                        return data;
                    }
                }


4D

For each ($oRecord; $oRecords)

// ADD TO DATATABLES (JSON)

If ($oRecord.active)

$txtActive:="<input type='checkbox' disabled='disabled' checked='checked'/>"

Else 

$txtActive:="<input type='checkbox' disabled='disabled'/>"

End if 

$oDataTable.push(New collection($oRecord.ID; $oRecord.name; $txtActive; ""))

End for each 

Edu Reyes Jr

unread,
Aug 28, 2021, 6:48:55 AM8/28/21
to lightning-...@googlegroups.com
Graham,

Thank you so much for this, I'll try this when I get back to work.

I tried to do that script side, but I think I might have messed up the syntax, so it's great to see this.

Again, thanks.

-Edu

--
You received this message because you are subscribed to a topic in the Google Groups "Lightning - 4D Web Applications" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lightning-4d-web-apps/ZidRBzBvg3Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lightning-4d-web...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lightning-4d-web-apps/dd501255-ed63-46cb-b843-524f3fff1c19n%40googlegroups.com.

Edu Reyes Jr

unread,
Aug 30, 2021, 5:26:41 AM8/30/21
to lightning-...@googlegroups.com
Graham,

I tried the script part and I'm getting an error.
voucher_list_error.png

Script:
voucher_list_script.png

4D
voucher_list_coll.png

I will now try the way in 4D


--

Edu Reyes Jr

unread,
Aug 30, 2021, 5:33:08 AM8/30/21
to lightning-...@googlegroups.com
Graham,

4D side works perfectly!
voucher_list_4D.png

voucher_list_4Dcode.png

Thank you for your help.

-Edu

On Sat, Aug 28, 2021 at 6:17 PM Graham Langley <graham...@hotmail.co.uk> wrote:
--

Edu Reyes Jr

unread,
Oct 25, 2021, 6:23:25 AM10/25/21
to Lightning - 4D Web Applications
Graham,

On 4D side, this code works well and I'm able to represent True/False on the web:

If ($oRecord.active)

$txtActive:="<input type='checkbox' disabled='disabled' checked='checked'/>"

Else 

$txtActive:="<input type='checkbox' disabled='disabled'/>"

End if 


Question is can I put an onclick ltgExecuteMethod with this?

I have an included form in the detail HTML which contains a checkbox. I'm having a little trouble with the correct syntax. I write:

If ($oPcp.attended)

$txtAttended:="<input type='checkbox' checked='checked' onclick=\"ltgExecuteMethod('PersonObject_checkbox',row[1])\" />"

Else 

$txtAttended:="<input type='checkbox' onclick=\"ltgExecuteMethod('PersonObject_checkbox',row[1])\" />"

End if 

and appears in the HTML like this:
cb_onclick_html.png

The method is not being called.

I tried other variations, and 4D likes to put double backslash.

I also tried putting the onclick ltgExecuteMethod in the HTML itself but it seems to have conflicts with the one in 4D,
 cb_onclick_codeHTML.png
(1) on display, the checkbox is unchecked even if the value is TRUE.
(2) on click, the method is called but by the end of it, there are errors in Navbar_SetActive says ") is missing"
So it seems that these two cannot be combined. (4D and HTML ltgltgExecuteMethod  )

Thanks.
-Edu

Edu Reyes Jr

unread,
Oct 25, 2021, 1:35:26 PM10/25/21
to Lightning - 4D Web Applications
I got the syntax right:
syntax.png


But I have more information on the error:

When refreshing the included form, I use:
ltgerror.png
I noticed that whenever $txtAttended is included in the $oDataTable push,
This error occurs:
nav_err.png

nav_err2.png

Graham Langley

unread,
Oct 26, 2021, 7:30:00 AM10/26/21
to Lightning - 4D Web Applications
If you are having errors in the browser complaining about argument lists, it will be about formatting errors, can you recheck your formatting and in future please post code examples as text, as opposed to screenshots, it makes it easier to check (no pun)

Edu Reyes Jr

unread,
Oct 26, 2021, 8:52:32 AM10/26/21
to Lightning - 4D Web Applications
I am not quite sure what you mean by "formatting".

Because I used what you  recommened (which works fine when displayed):

For each ($oRecord; $oRecords)

// ADD TO DATATABLES (JSON)

If ($oRecord.active)

$txtActive:="<input type='checkbox' disabled='disabled' checked='checked'/>"

Else 

$txtActive:="<input type='checkbox' disabled='disabled'/>"

End if 

$oDataTable.push(New collection($oRecord.ID; $oRecord.name; $txtActive; ""))

End for each 


I do some action and call a method which will call again the code above. And since this is an included form and we want the list to update right away, I use:

// CLEAR THE DATATABLE
Ltg_JS_Send("ltgObj('participant').DataTable().fnClearTable()")

// UPDATE THE ORDER ITEMS DATATABLE
If ($oDataTable.length>0)
Ltg_JS_Send("ltgObj('participant').DataTable().fnAddData(JSON.parse('"+JSON Stringify($oDataTable)+"'))")
End if 

And that error dialog appears.

But when I remove  $txtActive from the push, the error dialog goes away, but of course this is not what we want.

Graham Langley

unread,
Oct 29, 2021, 4:08:55 AM10/29/21
to Lightning - 4D Web Applications

Hello Edu,

Let’s go back to displaying the checkbox in the html, instead of generating in 4D.

Change parts of your ParticipantInclude_DataTable method to this;

If ($oParticipant.attended)
$txtAttended:="checked"
Else 
$txtAttended:=""
End if 

$oDataTable.push(New collection(""; $oParticipant.UUID; $txtAttended; $eventDate; $eventName; $txtAttended; String($oParticipant.amountDonated; "$###,###,##0.00"); ""))

and then in the html, add another <th> tag to the table like this;

 <th>
 <!--ATTENDED-->
 </th>

and then update the DataTables javascript to the below;

 {
                    targets: [ 1 ],
                    visible: false // UUID - HIDDEN
                },
                  {
                    targets: [ 2 ],
                    visible: false // ATTENDED - HIDDEN
                },
                {
                    targets: [ 3 ],

                     render: function ( data, type, row, meta ) {
                     if(type === 'display'){ 
                     
                      data = '<input type="checkbox" '+row[2]+' onclick="ltgExecuteMethod(\'EventParticipant_Attended\',this.checked+\'.'+row[1]+'\');"/>';
                     }
                     return data;
                    }                    
                },

Edu Reyes Jr

unread,
Nov 2, 2021, 4:33:52 AM11/2/21
to lightning-...@googlegroups.com
Graham,

Sorry for the late reply. I will try this today and give you feedback later on.

Thanks so much. 

- Edu

--
You received this message because you are subscribed to the Google Groups "Lightning - 4D Web Applications" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lightning-4d-web...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lightning-4d-web-apps/3024fb11-10d4-4f14-8a3d-7e6d52428de6n%40googlegroups.com.

Edu Reyes Jr

unread,
Nov 2, 2021, 10:38:29 AM11/2/21
to Lightning - 4D Web Applications
Graham,

It works perfectly. No more errors. This is great!

Thank you!

ltg_checkbox.png

Reply all
Reply to author
Forward
0 new messages