Archive for October, 2007

Download Pagination example

I received a couple of mails saying that the link to Bob Obringers article on his ‘ultimate view navigator’ is dead and if I could send a copy of the example.

I have uploaded a working example > here < including an example for a flat view and an example for a categorized view. In the flat view I have included Prototype’s AJAX request handler, the categorized view still uses Bob’s approach. Good luck!

page navigation example

Updated: the application had local encryption enabled…

Comments (3)

@If variant for aliases

For a computed text I needed to write down the value of a dialoglist field which uses aliases.

Luckily the number of options was limited, but for a list of long options I do not want to use this construction:

@If( condition1 ; action1 ; condition2 ; action2 ; … ; condition99 ; action99 ; else_action )

Therefor I came up with the following solution creating a text-list with options and then go through them using @Elements, @Right and @Left:

status:=”Draft|0″:
“Awaiting Approval|1″:
“Approved|2″:
“Archived|3″:
“Rejected|91″:
“Returned|92″;

@For(n := 1;n <= @Elements(status); n := n+1;
 rightvalue:=@Right(status[n];”|”);
 @If(rightvalue=Tx_Status;leftvalue:=@left(status[n];”|”);”")
);
leftvalue;

Comments (4)

Update: ‘Warning before…’

Here is an updated version of the JS header, now fully making benefit of prototype’s Event.observe event listener. Note: the code is not updated in the download link you can find here.

// SHOWING A WARNING WEN USERS LEAVE THE FORM WITHOUT SAVING
function formChange(){ 
 $(‘isChanged’).value=”1″;
}

window.onbeforeunload = confirmExit;

function confirmExit() { 
 if($F(‘isChanged’)==’1′){
  return “You have not saved the form yet. Are you sure ?”;
 }
}

Event.observe(window, ‘load’, init, false);

function init(){
 var inputs = $$(‘input.required’);
  for (var i = 0; i < inputs.length; i++) {
     Event.observe(inputs[i], ‘focus’, oninputfocus);
     Event.observe(inputs[i], ‘blur’, oninputblur);
  }
  var textareas = $$(‘textarea’);
  for (var i = 0; i < textareas.length; i++) {
     Event.observe(textareas[i], ‘focus’, oninputfocus);
     Event.observe(textareas[i], ‘blur’, oninputblur);
  }
}

var tempinputvalue =”";

function oninputblur(e) {
 if (typeof e == ‘undefined’) {
  var e = window.event;
 }
 var source;
 if (typeof e.target != ‘undefined’) {
  source = e.target;
 } else if (typeof e.srcElement != ‘undefined’) {
  source = e.srcElement;
 } else {
  return true;
  }
 if ($F(source) != tempinputvalue) {
  $(‘isChanged’).value=”1″
 } 
}

function oninputfocus(e){
 if (typeof e == ‘undefined’) {
  var e = window.event;
 }
 var source;
 if (typeof e.target != ‘undefined’) {
  source = e.target;
 } else if (typeof e.srcElement != ‘undefined’) {
  source = e.srcElement;
 } else {
  return true;
 }
 tempinputvalue = $F(source)
}
// END – SHOWING A WARNING WEN USERS LEAVE THE FORM WITHOUT SAVING

I noticed that WordPress uses a similar technique when writing posts.

Comments (4)

Update: ‘Warning before…’ – Demo

I have uploaded a demo application, yuk Notes 8 vocabulary, here for download. The default frameset contains a form. Fill in some data in the fields and try to leave the form. A following warning will show up:

demo screen

Enjoy!

Ps this database was saved with the Notes 8 Designer. Can anyone tell me where the ‘Save’ smarticon went? I could not find it while working on the form. Using the File-Menu-Save really is annoying?

While kicking Notes 8: what the hell must that ‘Preview in Web browser’ icon look like? Notes 8 smart icons: BAD!!!

Comments (1)

Warning before navigate away from a web form without save

This posting is merely a big ‘thank you’ to Philippe Gauvin’s posting ’Warning before navigate away from a web form without save’ and Simon Willison’s posting ‘Simple Tricks for More Usable Forms’.

Philippe describes how you can add a function that warns users when they intend to leave the window without actually saving the document. Simon describes the way how to add event listeners to forms, which is a great add-on Philippe’s article because Philippe ‘forgets’ to write how he implemented the code to work.

So what is the idea?

  • a users has a form opened
  • when he clicks on a link that leads him to another page a warning comes up if he really wants to leave the page without saving or if he wants to stay on the form so the document can be saved
  • the condition I added is: if there are changes made to required fields then I think the user has actually worked on interesting information, so in these cases the warning should pop-up.

In my example each required field has a classname ‘required’ (a bit based upon Andrew Tetlaw’s really kewl javascript form validation method). When there is a difference between entering the field and leaving the field a third field will change from value “0″ to “1″ which should initiate the warning.

Adding Eventlistening

I did not want to add into every single field a function that would check if there have been made changes, so on the windows load event we add an eventlistening. As soon as the user enters and leaves one of the ‘required’ fields we run an onfocus or an onblur function.

How to implement?

Just follow Philippe’s instructions. Basically I added a Notes field, gave it an id ‘IsChanged’, default value is set to “0″ and I made it hidden. Then I copied in the JSHeader of my form the first part of the code:

// SHOWING A WARNING WEN USERS LEAVE THE FORM WITHOUT SAVING
function formChange(){ 
 $(‘isChanged’).value=”1″;
}

window.onbeforeunload = confirmExit;

function confirmExit() { 
 if($F(‘isChanged’)==’1′)     return “You have not saved the form yet. Are you sure ?”;
}

(by the way, yes we use the Prototype library)

Second, based upon Simon’s article I added the next lines of code in the JS Header:

addEvent(window, ‘load’, function() {
  var input,textareas;
  var inputs = $$(‘input.required’);
  for (var i = 0; i < inputs.length; i++) {
     addEvent(inputs[i], ‘focus’, oninputfocus);
     addEvent(inputs[i], ‘blur’, oninputblur);
  }
  var textareas = $$(‘textarea’);
  for (var i = 0; i < textareas.length; i++) {
     addEvent(textareas[i], ‘focus’, oninputfocus);
     addEvent(textareas[i], ‘blur’, oninputblur);
  }
});

function addEvent(obj, evType, fn){
 if (obj.addEventListener){
     obj.addEventListener(evType, fn, false);
     return true;
  } else if (obj.attachEvent){
     var r = obj.attachEvent(“on”+evType, fn);
     return r;
  } else {
     return false;
  }
}

var tempinputvalue =”";

function oninputblur(e) {
 if (typeof e == ‘undefined’) {
  var e = window.event;
 }
 var source;
 if (typeof e.target != ‘undefined’) {
  source = e.target;
 } else if (typeof e.srcElement != ‘undefined’) {
  source = e.srcElement;
 } else {
  return true;
  }
 if ($F(source) != tempinputvalue) {
  $(‘isChanged’).value=”1″
 } 
}

function oninputfocus(e){
 if (typeof e == ‘undefined’) {
  var e = window.event;
 }
 var source;
 if (typeof e.target != ‘undefined’) {
  source = e.target;
 } else if (typeof e.srcElement != ‘undefined’) {
  source = e.srcElement;
 } else {
  return true;
 }
 tempinputvalue = $F(source)
}
// END – SHOWING A WARNING WEN USERS LEAVE THE FORM WITHOUT SAVING 

 This initates the event listening for the onblur and onfocus events of the fields with classname ‘required’. That’s it. I do not know how I can adjust the default warning popup, but I guess sure one of you know:

warning

Comments (1)

Calculating remaining characters in a field

On Assono’s blog I read a SnTT-article that demonstrates a way to show the remaining characters for a field on a Notes form. In his example the value are being written in a second field.

It reminded me about a similar request I had. A customer wanted to have (on a Domino form) several input fields below each other in stead of one textarea field. This would make it easier to write the data afterwards to a different system (each new field would resemble a breakline).  When the maximum number of characters has been entered the next field should be shown and get focus so the end-user could continue writing.

In my approach I used a <SPAN> tag in stead of an extra design element (field). The next image demonstrates what came up with (untill now):

remaining characters 

Since I have started working with the Prototype JS library recently (yes shame on me) , this was a nice case to try and implement it in an application.

What can illustrate maybe best how it works is the next image of the onKeyUp event:

onkeyup

Each field has on it’s right a <SPAN> tag. For each field is definited how it should behave, what it should show when and where. If the field-value has come to a certain length (a variable in the HTML Head Content) the next field should be displayed and have focus, on this condition that the current field contains the attribute “nextstep =  follow”. Therefor the last field in the example misses this extra attribute.

I also added 3 keycode events to the condition so no backspace, arrow left and arrow right is taking in notice.

In the onLoad event of the form I added the maxlength attribute from the JS variable to all concerning fields . I have noticed that in order to let Internet Explorer understands that you want to add a value to it you need to write ‘maxLength’ in stead of the expected ‘maxlength’…

onLoad of the form

Well that’s all! Here is a link to the sample application (like they like to say in Notes 8).

Comments (1)

SuperNTF – feature request

Somewhere in the sideline of this blog i wrote: “With this blog I am trying to give my contribution to the Lotus Notes community. “.

It seems that some thoughts/ideas/solutions do help people (thanks for emailing, yes I would to spend more time on answering them). While checking some statistics I noticed a link to OpenNTF. Since I am not such a contributor there I was curious and read this:

my suggestion

Thanks!, that’s stimulating enough to keep up with regular posting here :-)

Comments (2)

Get keyword function

Here a simple LotusScript function that I use quite a lot to get keyword values:

Function Get_Keyword(dbCurrent As NotesDatabase, sKey As String) As NotesDocument
 Dim viewKeywords As NotesView
 Dim docReturn As NotesDocument
 Set viewKeywords = dbCurrent.GetView(“v-keywords”)
 Set docReturn = viewKeywords.GetDocumentByKey(sKey)
 Set Get_Keyword = docReturn
End Function

Usage:

Set keyword = Get_Keyword(dbCurrent, “keyword_key”)

where keyword_key is the first fieldvalue in the view to search for…

Comments (3)