Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Sunday, May 19, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Web Forums - SalesLogix Web Client (Pre-7.2)
Forum to discuss using & developing the legacy SalesLogix Web Client (For versions 7.0 and earlier). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Web Client (Pre-7.2) | New ThreadView:  Search:  
 Author  Thread: Checkboxes in web client
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 7:40 AM
I have to create a form with over 60 checkboxes on it. The checkboxes will write to a 1 to 1 table off accounts. The fields are boolean. The screen will be a tab off accounts. This would be the first time I have done checkboxes in the SLX web client.

I have been looking at the 'Do not solicit' checkboxes on the Contact Detail screen.. It appears each one has a hidden text box and runs through a javascript function..

I have over 60 checkboxes (actually 120 as I need to do a contact version also) to deal with. Is there an easier way to do this than the method used with the 'do not solicit' checkboxes on the contact detail screen?

Thanks
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 10:28 AM
Yeah, there is, and it doesn't require a hidden control for each checkbox.

Lets say you have this:

<input type="checkbox" name="mycheckbox" value="<#F name=mycheckbox options=K>">

In the web action, to get if it's posted or not, you can do this:


If PostedGetValue("mycheckbox") = "on" Then
'** It's checked
PostedSetValue "mycheckbox", "T"
Else
'** It's not checked
PostedSetValue "mycheckbox", "F"
End If

The key being checking if the value equals "on". For an example (at least in 6.2.6) look at the "deleteactivity" action. Line 56 reads:


if PostedGetValue("actalarmcheck") = "on" then
PostedSetValue "actalarm", "T"
end if

The other approach I've used is to write a single javascript function that receives the checkbox as a control and you'd use the eval statement to take the control that was passed, get the name of the passed control, append a known, hard-coded character to "create" the name of the matching hidden control and set the value to the hidden control that way. That way, though, you still have to have a hidden text box for each checkbox. But if you name each hidden control the same as the checkbox but with something such as "_hdn" at the end, you can use the eval statement and have on JS function that sets the hidden text box value.

I much prefer the first method - no hidden controls.

Jeff
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 2:22 PM
Thanks Jeff. I defiantly prefer not coding 120 hidden text fields if possible..

I am able to update the fields, but they are not displaying back on the form as checked.. Here is the tag I am using:

<input name="accdescaccounting" type="checkbox" value="<#F name=accdescaccounting options=K>" >

Am I missing something? Thanks
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 3:40 PM
Quote:


<input name="accdescaccounting" type="checkbox" value="<#F name=accdescaccounting options=K>" >

Am I missing something? Thanks


Yeah, I forgot something. You'll see I added value=T in the <#F> tag.


<input name="accdescaccounting" type="checkbox" value="<#F name=accdescaccounting options=K value=T>" >


That tells the DLL that if the value returned by the alias = "T", return checked. That should do it.

Jeff
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 3:46 PM
<input type="checkbox" name="condonotsolicitdisplay" id="condonotsolicitdisplay" value="<#F name=condonotsolicit format=9 formatstring=T/F>" <#FIELD name=condonotsolicit value="T" options=K>>

The above example is from the Do Not Solicit checkbox on the Contact Detail view.
Notice the additional <#Field entry with the options=K. My assumption is that this entry returns a blank string if the value = "T" or "checked" if the value = "T"
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 3:52 PM
As an additional comment:

In html, the Checkbox is not set based on its "Value" but rather based on whether the item contains the Checked attribute:
<input name="c1" type="checkbox" value="True" > UnChecked
<input name="c2" type="checkbox" value="True" checked> Checked
<input name="c3" type="checkbox" value="True" checked="true"> Checked
<input name="c4" type="checkbox" value="True" checked="false"> Checked

This is why you add the <#field ... options=K> as part of the Input tag and not necessarily within the value attribute.
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 3:59 PM
Raul,

You're right. I've got the <#F options=K> all over the place without the "value=". Guess I didn't engage the brain before typing.

Jeff
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 4:05 PM
Jeff,

It happens to all of us... Just the other day I replied to a post without realizing it was web related and was giving a Windows code sample that you probably wouldn't want to run on the web.... Then again, I only had a couple of hours of sleep the previous night...


Raul
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 4:08 PM
Thanks to both of you.. almost there..

In the update script I am using this as Jeff suggested:
If PostedGetValue("accdescaccounting") = "on" Then
'** It's checked
PostedSetValue "accdescaccounting", "T"
Else
'** It's not checked
PostedSetValue "accdescaccounting", "F"
End If

Two things.. This only seems to evaluate to Else - so if I change the "F" to "T" in the else statement the value gets saved.. so I know it's saving.. just not sure why 'If PostedGetValue("accdescaccounting") = "on" Then..' never evaluates..

Also, I have 120 of these checkboxes to update. Is it possible to loop through the forms collection and dynamically update the values? Or do I have to write an IF THEN statement for each checkbox? (ugh!)

BTW - I can't wait to get my clients on 7.2 web!!

[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 4:33 PM
It may not be returning "on" because of my bad advice. If the value is being set to the "T" or "F", then when it posts back, it may have that actual value instead of "on"/

Try doing a

senderror "value is: " & PostedGetValue("accdescaccounting")
exit sub

and see what comes back. You'll get the "We apologize for the inconvenience page", but it should show you what the posted value is. I suspect you'll see "T" or "F".

Since my original statment had the value="<#F blah..blah...> on the checkbox, try this (it's a revision based on Raul's comments) to this:

<input name="accdescaccounting" type="checkbox" <#F name=accdescaccounting format=9 formatstring=T/F options=K value=T>>


The options=K should return checked, without assigning the value to the checkbox control (the value is completely removed). My apologies if my original code/suggestion steered you wrong.

Jeff
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 4:47 PM
Sweeeet. With the new tag it actually does return 'on'. So that is working. Thanks!!

One more question.. is it possible to loop throught the forms collection to update the checkboxes as opposed to writing an If/Else for every checkbox?

Perhaps something similar to this example from the web dev. guide, as far as looping goes? I know this isn't even close.. still digesting..

For I = 0 To PostedLineCount - 1
pName = PostedGetName(I)
pQty = PostedGetValue(pName)
If (IsAlias(pName) = False) And (pQty <> "") And (IsNumeric(pQty) = True) Then
dbHandle = CreateRecord("INSERT LITREQUESTITEM")
RecordAdd dbHandle, "litreqitemlitreqid", litreqid
RecordAdd dbHandle, "litreqitemlitid", pName
RecordAdd dbHandle, "litreqitemqty", pQty
LogSetGlobalId dbHandle, litreqaccid
PostRecord (dbHandle)
If LogixErrorCode <> 0 Then
AddLitItems = "There was an error adding a LITREQUESTITEM record: " & _
LogixErrorText
Exit Function
End If
SQLClause = "SELECT COST FROM LITERATURE WHERE LITERATUREID='" + pName + "'"
Print "SQL Clause = " & SQLClause
curritemprice = DoSQL(SQLClause, "1", "")
Print "current item price = " & curritemprice
Total = Total + (pQty * curritemprice)
Print "Total = " & Total
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 4:49 PM
Steve,

I just verified - if you do include the "<input type="checkbox" value="<#F name=testfield options=K>">, when it posts, PostedGetValue will return "checked". So that's probably what's happening to you. What you want to do is remove the value="<#F name=blah options=K>. What you should have is just the alias:

<#F name=aliasname format=9 formatstring=T/F options=K>

without the "value=" in front of it. As Raul pointed out, the above will return the word "CHECKED", checking the checkbox.

Sorry for the bad advice. Or at least advice without testing.

Jeff
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 4:51 PM
Steve,

If you set the value of the checkbox as per the example I provided, it will be set to "T" or "F".
And that is probably why it is always go to the Else portion of it.

So, what to do... Add a handler to the OnClick event as shown below:


function changeCheckbox(obj)
{
obj.value = obj.checked ? "T" : "F";
}
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 5:07 PM
Steve,

You're right on with what you want to do. That example is closer than you think.

You can probably use the "AddPostedValues" function in the global web action. You can see an example of it being called in the "addcontact" action and the actual code for AddPostedValues is in the global library.

The key to making the AddPostedValues is that whatever table name you pass as a parameter to AddPostedValues must be the table that your aliases start from. So, for example, if you pass in a table name of "Contact", your aliases for the page MUST start from the contact table and join as needed.

The other key is that your alias name MUST also match the control name. If your control name is "accdescaccounting", then your alias must also be named "accdescaccounting". This is because if you look in the AddPostedValues function there's a line that reads:


elseif IsAlias(S) and (AliasToTable(S) = Table) then


You'll see that it checks two things (what I outlined above):
1) The name of the posted control has an alias of the same name, and
2) The alias maps to the passed in table name as it's starting point (this should be the name of the table your template is based on).

You'll see that it then does the "RecordAdd" for you.

So, if you meet the two conditions, all you need to do is do your CreateRecord, call AddPostedValues passing in your Handle and the table, and then do a PostRecord.

You can even abstract this to a higher level, if you want. You can call the DoUpdate function (also in the global action) which does the CreateRecord for you, as well as call "AddPostedValues" and it also does the PostRecord. An example of "DoUpdate" being used is in the updatecontact action. Since it calls the AddPostedValues, again, make sure you name your aliases to match your controls and your aliases start at the table your template is based on.

If it were me, the easier is the "DoUpdate", because it eliminates you creating a handle and doing the PostRecord. I've had an action or two that pretty much does nothing but call "DoUpdate" and I'm done.

Does that make sense? If you try it and get stuck post again.

Jeff
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 5:19 PM
Quote:
So, what to do... Add a handler to the OnClick event as shown below:

Two other options:

1) Remove the


value="<#FIELD name=blah options=K value=T>"

from the checkbox. Unless you really need a value in the value attribute of the control, there's no need. The system will return "on" if it's checked or an empty string (I believe it's an empty string) when not checked. That way you can eliminate the javascript.

Or, 2) the other option, is server side do this:

If PostedGetValue("controlname") = "T" or PostedGetValue("controlname") = "on" Then
'**
Else
'** checked
End If


Jeff
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Sep 07 6:52 PM
Jeff:

Not sure if this is IE7, but I tried this on my end to no avail:

Test 1
<input id="check1" type="checkbox">
<input type="button" onclick="alert(document.all.check1.value);"value ="Test">

My test:
Click on the button after the page loads returned "on"
After I checked the checkbox, clicked on the button and it returned "on"
After I unchecked the checkbox, clicked on the button and it returned "on"

Test 2 (This time I set the value to blank on HTML
<input id="check1" value = '' type="checkbox">
<input type="button" onclick="alert(document.all.check1.value);"value ="Test">

My test:
Click on the button after the page loads returned ""
After I checked the checkbox, clicked on the button and it returned ""
After I unchecked the checkbox, clicked on the button and it returned ""

I recall having faced this issue in the past, thus always set the value according to my needs via scripting.

[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Sep 07 9:02 AM
My web server is down this morning, but wondering if this might work:

Sub Main
For I = 0 To PostedLineCount - 1

If PostedGetValue(PostedGetName(I)) = "on" Then
PostedSetValue PostedGetName(I), "T"
Else
PostedSetValue PostedGetName(I), "F"
End If
Next

LogSetGlobalId dbHandle, PostedGetValue("accid")
DoUpdate "ACCOUNT", "accid"

end sub

Next

[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Sep 07 10:47 AM
Raul,

It looks as if you're checking the value client side - I was checking the value of the checkbox for "on" only on server side.

Here's my code:

I added this to the template coninfo:

<input type="checkbox" name="testfield" <#F name=testfield format=9 formatstring=T/F options=K>>


I created a field named "TESTFIELD" on a table called C_CONTACT_TEST as an SLXBoolean.

Then I created an alias called "testfield" with the following data path and path in the DB:

Contact.C_CONTACT_TEST.TESTFIELD (datapath)
CONTACT:CONTACTID>CONTACTID.C_CONTACT_TEST!TESTFIELD (path field from slxwebalias)


In the action "updatecontact", I added this right after all the "stripphone" statements:

senderror "testfield value: |" & PostedGetValue("testfield") & "|"
exit sub


Whenever the form posts and the senderror is sent, if the field is checked, it returns "on" on the "we apologize" page. If it's unchecked, it returns the emtpy string.

Client side, I never actually check the value property of a checkbox; I simply look to see if the "checked" property is true.

Jeff
[Reply][Quote]
Jeff Ballard
Posts: 326
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Sep 07 10:49 AM
Steve,

I haven't run the code, but that looks like it should work as long as the control names and alias names match.

Did the web server completely die? That would make for a bad day! Had it happen to a customer in production a few weeks ago. It was a long day rebuilding and reinstalling...

Jeff


[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Checkboxes in web clientYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Sep 07 10:57 AM
Web server is actually fine. You are right, that would make for a bad day. They are migrating data into the DB I have the web set up on, so I don't have any records to test against and am steering clear for best practice. Hopefully I will be able to test later today.

I'll let you know how I make out. I used to use similar code in classic asp - I could usually use the same code to update any form with control and field names the same - just wasn't sure of the commands in the SLX web. Beats 120 If then statements any day.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 5/19/2024 11:08:59 PM