dominoGuru.com

Your Development & Design Resource

Computed Text, Select and Input Elements, and the home grown Domino Form

As I had mentioned in my last post - using a FIELD element in your home grown Domino Forms markup to display a given fields content is a quick and easy way to get around the need for <Computed Text> elements - but that only really works for single valyue Input and Textarea elements on your form. You'll run into a problem quite frankly when you try to use any other element type that gathers input from a user, such as a Select or Input (checkbox or radio) elements.

To get around this, I typically do rely on the <Computed Text> elements, and storing all options for my fields in a "profile" document -

I say "profile" document, because it's not a LND-styled Profile Document, as I've found that HTTP Task caching can cause pains when you're storing things like keywords or other various content. I've even seen very old content magically re-appear in the Profile Document, which can be quite a problem. And I'm using a document and not storing these items as part of the design because I want to give Database Administrators et al the ability to maintain their own applications...

- So I'll store my keywords and other such content on a profile document that I'll call "preferences". Now, for my <Computed Text> element Formula. I'll show you that with the markup for a typical select field:

<select name="test" id="test">
<Computed Text>
</select>

The <Computed Text> elements Formula:

key := "test";
val := @DBLookup("":"NoCache";"":"";"bykey";"preferences";key;[FailSilent]);

@For (
n := 1;
n <= @Elements(val);
n := n + 1;
@If(
 @IsMember(val[n];test);
 markup := markup : @Text("<option selected value=\"" + val[n] + "\">" + val[n] + "</option>");
 markup := markup : @Text("<option value=\"" + val[n] + "\">" + val[n] + "</option>")
)
);

@Implode(markup)

Now, this works for Select elements, but we also have Input (checkboxes and radiobuttons) to consider. Checkboxes and radiobuttons differ in that you can select multiple items with the checkboxes, while only a single option can be selected for the radio button (duh! - I know, but it warrants comment for what's coming up). So we'll need to modify our formula to accomodate their element-function requirements.

Checkboxes:

key := "test";
val := @DBLookup("":"NoCache";"":"";"bykey";"preferences";key;[FailSilent]);

@For (
n := 1;
n <= @Elements(val);
n := n + 1;
@If(
 @IsMember(val[n];test);
 markup := markup : @Text("<input type=\"checkbox\" name=\"test\" id=\"test_" + @Text(n) + "\" checked value=\"" + val[n] + "\" /><label for=\"test_" + @Text(n) + "\">" + val[n] + "</label><br />");
 markup := markup : @Text("<input type=\"checkbox\" name=\"test\" id=\"test_" + @Text(n) + "\" value=\"" + val[n] + "\" /><label for=\"test_" + @Text(n) + "\">" + val[n] + "</label><br />");
)
);

@Implode(markup)

And Radiobuttons:

key := "test";
val := @DBLookup("":"NoCache";"":"";"bykey";"preferences";key;[FailSilent]);

@For (
n := 1;
n <= @Elements(val);
n := n + 1;
@If(
 @IsMember(val[n];test);
 markup := markup : @Text("<input type=\"radio\" name=\"test\" id=\"test_" + @Text(n) + "\" checked value=\"" + val[n] + "\" /><label for=\"test_" + @Text(n) + "\">" + val[n] + "</label><br />");
 markup := markup : @Text("<input type=\"radio\" name=\"test\" id=\"test_" + @Text(n) + "\" value=\"" + val[n] + "\" /><label for=\"test_" + @Text(n) + "\">" + val[n] + "</label><br />");
)
);

@Implode(markup)

And that's pretty much it. Now, this code can be cleaned up, but I thought that I would keep it as easy to read is possible. Our next move, and hopefully something that I can get out there in the next few days, will be a downloadable example of a database that uses these approaches for it's hand made Domino Forms!


About the author: Chris Toohey

Thought Leadership, Web & Mobile Application Development, Solutions Integration, Technical Writing & Mentoring

A published developer and webmaster of dominoGuru.com, Chris Toohey specializes in platform application development, solutions integration, and evangelism of platform capabilities and best practices.



More from dominoGuru.com


dominoGuru.com is powered by IBM Notes Domino XPages & hosted by Prominic.NET

Contact Us

Use our Contact / Feedback form or one of these email addresses:

Creative Commons License

Except where otherwise noted, dominoGuru.com by Chris Toohey is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.