Skip to main content
 
developerWorks
AIX and UNIX
Information Mgmt
Lotus
New to Lotus
Products
How to buy
Downloads
Live demos
Technical library
Training
Support
Forums & community
Events
Rational
Tivoli
WebSphere
Java™ technology
Linux
Open source
SOA and Web services
Web development
XML
My developerWorks
About dW
Submit content
Feedback



developerWorks  >  Lotus  >  Forums & community  >  Notes/Domino 4 and 5 Forum

Notes/Domino 4 and 5 Forum

developerWorks

  


Solution - Un-check a checkbox in web browser
Jim J Imbrogno 5.Jun.02 01:30 PM a Web browser
Domino Designer -- LotusScript 5.0.7a Windows 2000

This is a long post. There's lots of info and functioning code.

I'm using R5.07a on Windows 2000 and MS-IE 5.5 SP-1

Here's the solution to the browser checkbox problem. The problem is that checkbox field isn't saved when:
1) you UN-check a checkbox with only one choice, or
2) you UN-check the last remaining option in a list of choices
(Note I said "last remaining option". This could be an option anywhere in the list, not just the last option at the bottom of the list.)

The problem only occurs when using Javascript's "submit()" method to save the doc in the browser. For example: document.forms[0].submit()
The problem does not occur if you are using "@Command([FileSave]); @Command([FileCloseWindow]);" to save the doc.
I needed to use "submit()" for other reasons, so I needed to get these checkboxes working.

It's also possible that the options to "Automatically refresh fields" and the keyword fields' option to "Refresh fields on keyword change" are part of the problem. I needed these options enabled, too, so let's continue.


Here are my settings:

Database properties > Basics
Enable the option for: "Web Access: Use JavaScript when generating pages"

Form properties > Defaults
Enable the option for: "On Web Access: Generate HTML for all fields"
Form properties > Form Info
Enable the option for: "Options: Automatically refresh fields"

For checkbox fields with single choice options:
First, some background:
I found this suggestion, but couldn't get it working (even after I corrected the erroneous "{<FIELD TYPE..." with "{<INPUT TYPE..."):

{<INPUT TYPE="Hidden" NAME="FieldName" VALUE=FieldName>}
This should be placed immediately before the actual checkbox field. Note the lack of quotes around the VALUE setting.

However, I was able to get this suggestion working (after I corrected an erroneous "onChange" to "onClick" since the Checkbox object doesn't respond to the onChange event, but it does respond to onClick.):

add a dummy field MyStatus
in the onClick event of the checkbox add something like

if(this.checked)
document.forms[0].MyStatus.value=1
else
document.forms[0].MyStatus.value=0

then in the translation formula of your checkbox add
@If(MyStatus="1";"1";"")

Here's my working code:

I defined a "Buyer_Status" field on my form design which is Text type and Editable. I believe it can be positioned anywhere on the form, either before or after the Buyer field.
This field is hidden both from Notes clients and Web browsers. There are no formulas in this field definition.

I defined a "Buyer" field as a Checkbox type field that is Editable. This is displayed to the User. I believe it can be positioned anywhere on the form, either before or after the Buyer field.
The choices value is a single line item: Buyer|Y (Note the alias character followed by "Y". This is optional.)

Input Translation formula:
rem "for the Notes side, set the ...Status field used by the web browser in case this doc gets edited by Notes and then the web.";
field Buyer_Status := Buyer_Status;

@If(@ClientType = "Notes";
@Do(
@SetField("Buyer_Status"; Buyer);
@Return(Buyer)
);
"");
@If(Buyer_Status = ""; ""; Buyer_Status);

onClick event:
if(this.checked == true)
{
document.forms[0].Buyer_Status.value=this.value;
}
else
{
document.forms[0].Buyer_Status.value="";
}

Here's how it works:
1) On the Notes client, the Input Translation formula preserves the checkbox setting. It appears that the onClick event isn't executed in Notes. So, the Buyer_Status field must be also updated by the Input Translation formula. If the doc is edited in Notes, then in a browser, the values set in Notes will be preserved when the browser saves the doc, because the values are also in the web-side's Approver_Status field.
2) On the Web side, the onClick event populates the Buyer_Status field with a value that indicates whether the checkbox is being checked or un-checked. Note that I tried to set the value of the Buyer field with document.forms[0].Buyer.value="Y", but that change wasn't saved either.
The Input Translation formula finishes the job by looking at what's now in Buyer_Status and placing the appropriate value in the Buyer field. If I wasn't using an alias of "Y", my Input Translation formula would have looked like this: .... @If(Buyer_Status = "Y"; "Buyer"; "");

For checkbox fields with multiple choice options:
This was a bit more challenging.

As in the above scenarion, I defined an "Approver_Status" field on my form design which is Text type and Editable. This field is hidden both from Notes clients and Web browsers. But this one is defined to "Allow multiple values", and it has the following Default Value formula:
rem "Placeholders for each element in the keyword list choices";
"N" : "N"

Look ahead and you'll see that there is one element for each choice in the Approver field's choices list.

I defined an "Approver" field as a Checkbox type field that is Editable. This is displayed to the User.
The choices list contains two items (without any alias values) :
PO Approver
Req Approver

Input Translation formula (which is a bit different from the scenario above):
rem "for the Notes side, set the ...Status field used by the web browser in case this doc gets edited by Notes and then the web.";
field Approver_Status := Approver_Status;

rem "Construct a complete list, with placeholder values of 'N' ";
rem "It must be in the same sequence as the keyword list choices.";
T_Approver := (
@If( @IsMember( "PO Approver" ; Approver ); "PO Approver"; "N") :
@If( @IsMember( "Req Approver" ; Approver ); "Req Approver"; "N")
);

@If(@ClientType = "Notes";
@Do(
@SetField("Approver_Status"; T_Approver);
@Return(Approver)
);
"");
@Trim(@Replace( Approver_Status ; "N" ; "" ))

onClick event:
// A Lotus bug doesn't change the value to null when UN-checking a checkbox.
// But the "checked" property is properly set to false when un-checking.
// So this work-around solves the problem.
// See Input Translation for
/*
Choices for this keyword list:
PO Approver
Req Approver
*/

var multiValuedField = document.forms[0].Approver_Status.value;

// The value in "re" tells the split function to look for 0 or more (*) spaces (\s)
// followed by a comma (,) followed by 0 or more (*) spaces (\s)
re = /\s*,\s*/; // re(gular expression) separator value) The forward slashes surround the match pattern.

// populate the working array
var myArray = multiValuedField.split( re );

// debugging aids
// alert ( "The array has " + myArray.length + " elements" );
// alert( "Element 0 = {" + myArray[0] + "}" + "\x0D" + "Element 1 = {" + myArray[1] + "}");
// The "\x0D" and an "unescape("%0D")" are the same. Both produce a carriage return.

// Each element in the choices list generates a separate HTML string to display the checkbox for each element.;
// For example: <INPUT TYPE=checkbox NAME="Approver" VALUE="PO Approver";
// Each statement has the VALUE portion set for one specific element's choice value;

// The "{{" and "}}" surrounding the "if(this.checked == true)" statement is used only for visual clarification
// to indicate that the "else" belongs to the "if(this.checked == true)" statement.

// Test for check / uncheck of the "PO Approver" checkbox
if(this.value == "PO Approver")
{{
if(this.checked == true)
{
myArray[0]=this.value;
// alert("PO Approver ON");
}
else
{
myArray[0]="N";
// alert("PO Approver OFF");
}} // end of- if(this.checked == true)
} // end of- if(this.value == "PO Approver")

// Test for check / uncheck of the "Req Approver" checkbox
if(this.value == "Req Approver")
{{
if(this.checked == true)
{
myArray[1]=this.value;
// alert("Req Approver ON");
}
else
{
myArray[1]="N";
// alert("Req Approver OFF");
}} // end of- if(this.checked == true)
} // end of- if(this.value == "PO Approver")

// now, write the array back to the multi-valued field
document.forms[0].Approver_Status.value = myArray.valueOf();

Here's how it works:
1) On the Notes client, the Input Translation formula preserves the checkbox setting. It appears that the onClick event isn't executed in Notes. So, the Approver_Status field must be also updated by the Input Translation formula.
2) On the Web side, the onClick event populates specific elements of the multi-valued Buyer_Status field with a value that indicates whether the checkbox is being checked or un-checked for that particular element.
The Input Translation formula finishes the job by replacing the "N" elements with null, applying @Trim to remove them, and placing the resulting selected list into the Approver field.


Also, if you execute a doc.Save during the PostSave event, you must make these adjustments to the PostSave event code:

'<<< EXTRA SPECIAL IMPORTANT NOTICE >>>

'The Input Translation formula of the Buyer field (and others) executes a @SetField to change the
' value of Buyer_Status, etc. This is part of the Lotus Checkbox Bug fix I developed (w/ help from Notes forum).
'Then, in the "SWF_Save" code called by this PostSave, other fields are modified, requiring me to
' execute a "doc.Save" in that code.
'Under these circumstances, the changes made by the Input Translation formula were being saved, BUT,
' they were then being overwritten by the doc.Save during the PostSave event.
'The doc.Save was saving data from a different memory object than the one that was updated by the
' Input Translation formula.
'Although the field values populated with @SetField were properly saved when the doc was saved by the user,
' the new field weren't being shown in the UIdoc object. So executing the doc.Save during PostSave overwrote
' those fields with the values that were still in the stale UIdoc / doc object in memory.

'This is sort of described by Lotus' Julie Kadashevich in an LDD posting where she said:
'The in-memory value is not updated because it would create major ineffeciencies for everyone in order to handle
'this relatively uncommon situation without needing to flush the stale in-memory value, so this is a "behavior" not a bug.

'The fix to allow me to update additional fields during PostSave and save those changes is to
' purge (Delete) the backend "doc" object and re-acquire it from the saved version already on disk.
'Without the "Delete doc" statement, trying to "Set ReAccessedDoc = db.GetDocumentByUNID( DocID )" simply
' uses the stale in-memory values. So it's important to delete that doc object from memory.

'I defined a new notesDocument object (ReAccessedDoc) for better understanding.
'I could have re-used the same "doc" object like this: "Set doc = db.GetDocumentByUNID( DocID )"
'But, the improved readability was important to me.

Dim doc As notesDocument
Set doc = Source.Document

Dim DocID As String
DocID = doc.UniversalID

Delete doc
' Delete Source

Dim session As New notesSession
Dim db As notesDatabase
Set db = session.CurrentDatabase


Dim ReAccessedDoc As notesDocument
Set ReAccessedDoc = db.GetDocumentByUNID( DocID )

If Not ReAccessedDoc Is Nothing Then

'Update some additional fields after a successful save
'Yes, this should be called during PostSave on the Notes side, and QuerySave on the Web side
Call SWF_Save ( ReAccessedDoc )


'Need to close & re-open the uidoc to reflect the changes made to ReAccessedDoc in the backend
'Otherwise, if further changes are made in the UIDoc, the User gets a Save conflict warning
Dim ws As New notesUIWorkspace
Dim ReAccessedUIDoc As notesUIDocument
Set ReAccessedUIDoc = ws.EditDocument( True, ReAccessedDoc)
Call Source.close

End If 'Not ReAccessedDoc Is Nothing

Regards.
Jim Imbrogno
Cleveland, OH

P.S.
I just discovered a problem with the PostSave process. Using the "ReAccessedDoc" causes the UIDoc to get a Save Conflict warning. I might have to move some of this functionality to the QueryClose event.

I'll post an update if I can.

I posted the fix at the end of the PostSave code above.

Keywords: "not saving"

Update - 6/6/02
I recently discovered another problem with my approach. In earlier testing, I became convinced that I had to update some fields (in Notes client) in PostSave, because doing it in QuerySave wasn't working.

This led to the extra work to open the ReAccessedDoc for PostSave update, and the close & re-open of the uiDoc to avoid Save Conflicts.

But using "Delete doc" is sometimes causing me other problems - like the Red Box of Death" crash with "Invalid Handle" or "Invalid Object" errors.

I just tried moving my PostSave code back to QuerySave, and removed the "doc.Save" and the ReAccessedDoc stuff. Magically, it seems to be working OK now!

Jim




Solution - Un-check a checkbox in w... (Jim J Imbrogno 5.Jun.02)
. . RE: Solution - Un-check a checkbox ... (Dovid Gross 5.Jun.02)
. . RE: Solution - Un-check a checkbox ... (Dovid Gross 5.Jun.02)
. . . . Good points! (Un-check a checkbox i... (Jim J Imbrogno 6.Jun.02)






  Document options
Print this pagePrint this page

 Search this forum

  Forum views and search
Date (threaded)
Date (flat)
With excerpt
Author
Category
Platform
Release
Advanced search


 RSS feedsRSS
All forum posts RSS
All main topics RSS
More Lotus RSS feeds

 Resources
Forum use and etiquette
Native Notes Access
Web site Feedback

  Lotus Support
Lotus Support
Product support pages index
Search knowledge base (Technotes)
Search support downloads
Lotus Support RSS

 Wikis
IBM Composite Applications
IBM Mashup Center
IBM Connections
IBM Docs
IBM Forms
IBM Mobile Connect
IBM Sametime
IBM SmartCloud for Social Business
IBM Web Experience Factory
Lotus Domino
Lotus Domino Designer
Lotus Expeditor
Lotus Foundations
Lotus iNotes
Lotus Instructor Community Courseware
Lotus Notes
Lotus Notes & Domino Application Development
Lotus Notes Traveler
Lotus Protector
Lotus Quickr
Lotus Symphony
IBM Web Content Manager
WebSphere Portal

 Lotus Forums
Notes/Domino 9.0
Notes/Domino 8.5 + Traveler
Notes/Domino XPages development forum
Notes/Domino 8
Notes/Domino 6 and 7
Notes/Domino 4 and 5
IBM Connections
IBM Forms
IBM Mobile Connect
IBM Sametime
IBM SmartCloud Notes
IBM SmartCloud Meetings
IBM Web Content Manager
Lotus Domino Document Manager
Lotus e-learning
Lotus Enterprise Integration
Lotus Expeditor
Lotus Protector
Lotus Quickr
Lotus SmartSuite
Lotus Symphony
Lotus Symphony Developer Toolkit Support
Lotus Workflow