Refreshing a document on a browser

Hi,I’m trying to refresh values in a pull down list on a document in edit mode on a browser from a domino database. I have turned on the use javascript when generating pages in the database properties. I have set the first dialog box field with the property: refresh fields on keyword change. I have set the second dialog box field with the property: refresh choices on document refresh. When I change the value for the first dialog box on a browser, the document does refresh, but reverts the value in the first dialog box back to what the value was when the document was first opened on the browser. The url in the address box is appended with this text: &Seq=1#_RefreshKW_district

district is the field name of the first dialog box field. In the log.nsf file, I find the command request=POST [url]&Seq=1. Each time I change the value of the district field, the command changes to &Seq=2, &Seq=3, etc…

Is there an obvious way to get the document I am editing to refresh the choices on the second dialog box field only and retain the in memory value in the first dialog box wihout actually saving the document? (since saving the document will kick off a web query save event that I don’t want to run just because the document is refreshing).

I’m about to change my tatic and write an agent that will compute this docment for me upon refresh, but before I do that I wanted to make sure someone else didn’t have a “why don’t you do this?” or a “did you do this?” comment first.

Thanks,

Heather Smith

Subject: refreshing a document on a browser

Hey, Heather!

What is the default value of your first dialog box? When you refresh the document, it will return to the default value. Try putting your default value to “@ThisValue”, and give it a go. If that doesn’t help, give us the default value of each of the two list fields.

Alternatively, you could use javascript to update the values of the two lists, and it won’t refresh the document. Just a thought… :slight_smile:

HTH!

Steve in NYC

“If the automobile had followed the same development cycle as the computer, a Rolls-Royce would today cost $100, get a million miles per gallon, and explode once a year, killing everyone inside.”

Subject: RE: refreshing a document on a browser

Steve,Thanks, I’ve tried no default value and a default value of the field name. I tried @thisvalue as a default value for each field. I got the same results. I wouldn’t mind doing it in javascript but javascript and I have never gotten along. :slight_smile: Do you have any examples in javascript of how I could do this?

Thank you,

Heather

Subject: refreshing a document on a browser

There are ways to do this, but it’s really best to avoid it. The best way is to use AJAX techniques with either XML or JSON objects containing your data. For this problem, there are quite a few example databases floating around (jake howlett’s codestore.net should have something close to what you want). What you are looking to do is, in the onChange event for the first combobox, have a function call that gets the xml based on the value in the first combobox, then parses the xml to determine what should be selected in the second combobox.

If this is an IE only solution, you might also look at the Keyword Refresh 2.0 project on codestore (in the sandbox there), as this uses a Data Island and does not have the requirement of needing to know all the things in the ajax version.

Also, having said all of that, just to be clear, when you select one option in the first combobox, you want it to change the option in the second combobox, is that correct? Or do you want to load the options in the second combobox from somewhere based on what is in the first combobox? Both are very doable using javascript.

I can send you an example of how to do this with ajax, if you would like.

Subject: RE: refreshing a document on a browser

Joel,Thanks. It’s not an IE only solution.

I want to change the options in the second dialog box when the value in the first dialog box is changed. I am building the choices with a formula. The values in the second field is based on the value in the first field.

I would like to see an example in ajax if you have one!

Best regards,

Heather

Subject: RE: refreshing a document on a browser

Where are you storing your choices? Can you post the method here where you’re doing this? In order to do this with AJAX (using xml or JSON) there has to be a relationship there someplace that we can use to say “values x, y, and z should be in box 2 when box 1 contains a”. How we do this will depend on where your choices are coming from in the first place.

This example uses only the prototype library, and as such, other frameworks may provide a slightly easier way of doing this. Download the prototype library and then import it into the database as a javascript library. In the js header on the form, insert a resource pointer to this library.

The code below is entered directly onto the form and marked as html. It should go above your fields. As you can see, my first field is departments, and the dependant field is depnumber. I have created two documents to store this data. The first one contains all of the store numbers, and the second all of the department numbers. In my environment, whenever the form containing the fields is opened, I have an onLoad event that triggers and updates the two storage documents from their respective databases. This is simply to ensure that I am working with the most up to date information and any method you like can be used to do this, if it is even needed. The key here, is the formatting of the view to create the xml. I have a view with an alias of stores.xml with two columns:

Col 1

“<department name="” + kDiv + “">” where kDiv is the department name field (the FIRST FIELD)

Col 2

@Implode(“” + kStore + “”) where kStore is the field that contains all of the stores (the SECOND, DEPENDANT FIELD)

Col 3

“</department”> used to close off the tag at the end of each row in the view.

This provides me with xml output like so for each document row:

1

2

1

2

3

4

This view is embedded in a ViewTemplate for stores.xml form (standard view template name)

Above the view is

<?xml version="1.0" encoding="UTF-8"?>

which handles namespacing the xml and below the view is the closing tag of

The embedded view property selected is Display using xml, of course, and for good measure, in the VIEW properties (5th tab), choose treat view contents as html.


<script>

	 function populate()

	 {

	 		var url = 'http://domino2.steinmart.com/TestAjaxKeywordList.nsf/stores.xml?openview';

	 		var myAjax = new Ajax.Request(

	 		 		 url, 

	 		 		 {

	 		 		 		method: 'get', 

	 		 		 		onComplete: showResponse

	 		 		 });

	 }

	 function showResponse(originalRequest)

	 {

			//$('result').value = originalRequest.responseText;

			//window.alert(originalRequest.responseText);

			var empID = document.forms[0].departments.options[document.forms[0].departments.selectedIndex].text

			//window.alert(empID);



			var xmlDoc = originalRequest.responseXML.documentElement;//not being seen by firefox

			//window.alert(xmlDoc);



			var entriesNode = xmlDoc.selectSingleNode("//department[@name='" + empID + "']");

			var entries = entriesNode.selectNodes("model");

			//window.alert(entries);



			//Remove current options!!

			document.forms[0].depnumber.length = 0;

			//window.alert(document.forms[0].depnumber.length);



			//Add new options container!!

			leng = entries.length;

			window.alert(leng);



			document.forms[0].depnumber.length = leng; 

			window.alert(document.forms[0].depnumber.length);



			//Loop through the "child" nodes and add all the new values...	

			for (var i=0; i < entries.length; i++){

				document.forms[0].depnumber[i].text = entries[i].text;

				document.forms[0].depnumber[i].selected=false;

			}

			document.forms[0].depnumber[0].selected=true;

	 }

regular notes fields go here on the form. The onChange event should call the populate() function.


Even though I used a view, any method of creating valid xml can be used. I have other applications which change the selected value of a combobox using an agent (just use that url in the xml line instead of the view url) which looks up a Vendor Name based on a Vendor Number entered, OR, looks up the vendor numbers for a vendor name entered. One of the powers of AJAX is that you can return data however you need it from your agent or view… it’s all xml, just format it as you need, then grab the text with your javascript (the showResponse function handles this in the example given).

Subject: RE: refreshing a document on a browser

Joel,Did you had any problems with the AJAX technique?. I used AJAX with Prototype.js to load options for ‘subsystem’ select box, based on ‘System’ box. That went well. But those options are not available once the document is submitted and open for editing.

In simple words, data persistance problem with AJAX.

Please share your experience.

Adi

Subject: RE: refreshing a document on a browser

Actually, I’d think your problem with persistance, as I read it, would be with any javascript loading technique, or a client-side application loading the values through scripting. When you load the page, what do you put in the box? For instance, in the application I just described, the second example, I do a simple @dbcolumn to load both my boxes whenever the page loads. For the first example (where the choices in the combobox, and not just the selected choice, are based on the first field, the question becomes what are your options in that box when you load it for editing? If populating the box is triggered by the onChange of the first field ONLY, whenever you do a page load (which you do when you change from read to edit mode, or open a document) on the web, what will be in your options array for that field? NOTHING. This will need to be accounted for in the onLoad event or some other event that can populate the choices before you get to it. Probably the simplist way would be in the onLoad, to check the value of the first field, and populate the choices in the second field. In short, write all your functionality as a function, and call the same function in the onLoad, and the onChange. Just remember to check for any “invalid” entry that might be the default so you don’t try to populate the second field based on a value of “Select an option here…” or some such that is often found in option boxes.

Subject: RE: refreshing a document on a browser

I’m already doing what you said. But i’m looking in the lines of writing ‘Select’, using javascript and put the notes field with the same name. I don’t know whether it solve the purpose or not. Let me give a try…

Adi

Subject: RE: refreshing a document on a browser

Even if you create the select field yourself in html, it would still have to be populated from somewhere when the page is loaded. I have an application where I do this for formatting reasons with checkboxes, but that one simply uses @formulae to build the checkboxes. The data comes from a profile document using a normal @getprofilefield. Regardless of whether you use the Notes controls/fields or roll your own with html, something still has to populate that field’s options when the page loads each time: either a notes formula or javascript. Unless I’m missing something in the intent, I don’t believe that creating the combobox via html or javascript dom manipulation will really gain you anything useful in this case.