xhrPost to Domino
Category xhrPost Domino Dojo
Bookmark :
Hi, David Bockes here. I've been working on a pretty extensive Dojo & Domino application. I have quite a few things that I should be blogging that have come out of this project that may be of interest, however I have been lax to do so. But, I'm going to try and correct that now. So, let's start with an issue that came up when trying to post a form back to the Domino server using xhrPost to save through Ajax.
I noticed that I would get inconsistant save results and that sometimes all the data in the form would save correctly and sometimes it would cutoff the data at a certain point. I then found that this would be based on whether or not data had been entered into fields that had been set as widgets (in this case the DateTextBox widget). The field had been defined as a widget by adding the following to the html attributes:
dojoType="dijit.form.DateTextBox" constraints="{datePattern: 'dd-MM-yyyy'}" required="true" promptMessage="dd/mm/yyyy" invalidMessage="Invalid date. Use dd/mm/yyyy format."
When sent to the browser, the outputted html for this field looks like this:
input name="ir_lh_Incident_Date" value="" dojoType="dijit.form.DateTextBox" constraints="{datePattern: 'dd-MM-yyyy'}" required="true" promptMessage="dd/mm/yyyy" invalidMessage="Invalid date. Use dd/mm/yyyy format." id="ir_lh_Incident_Date"
Note that in addition to a name, I also made sure to add an id in the properties box for this field (a good best practice for your Dojo stuff). Now, when this is parsed by dojo, the resulting html looks like this:
input id="ir_lh_Incident_Date" class="" type="text" autocomplete="off" dojoattachevent="onfocus,onblur:_onMouse,onkeyup,onkeypress:_onKeyPress" dojoattachpoint="textbox,focusNode" tabindex="0" value="" aaa:valuenow="" aaa:invalid="true" aaa:disabled="false" style=""
input type="text" value="" style="display: none;" name="ir_lh_Incident_Date"
Notice that two fields are created, one only has an id and no name and is the displayed version of the field that will show the date picker when clicked on. Right beneath that is a hidden version of the field that has a name but no id. When this form is submitted, the value from the display field is placed in the hidden field and is what gets saved into our document. However, the problem with the data save problems is due to the display version of the field. Domino is looking to match up the fields based on the name, not the id. The display version has no name, just an id. Now, you'd think that this would just get ignored, but it didn't.
I attempted to correct the issue in a WebQuerySave agent both by trying to strip out the no name fields or to only get the named fields and copy those. However this, since it's kinda a buggy problem, didn't work. So instead we took the approach of preventing the no name fields from being submitted in the first place. This was done by editing the Dojo source code and recompiling the custom Dojo build that I'm using.
To fix this, we have to use a "source" version of Dojo. A source version has the code that makes up the dojo.js and dijit.js split out into individual js files. In this case, we needed to edit the dojo\_base\xhr.js file. In there is a function called "formToObject" that is called as part of the xhrPost process. This function uses a dojo query to get only form elements on the page to submit to the server, leaving behind everything else. The key line for us is:
var iq = "input:not([type=file]) :not([type=submit]) :not([type=image]) :not([type=reset]) :not([type=button]), select, textarea";
This line builds the query to be used. Notice that it contains inclusions and exclusions (i.e., :not). The fix was to change the line to:
var iq = "input:not([type=file]) :not([type=submit]) :not([type=image]) :not([type=reset]) :not([type=button])[name], select, textarea";
Notice the inclusion of "[name]". This tells the query that the required item has to have a name attribute, if not, it is to be excluded. After making this change and recompiling the custom build, the problem was resolved. The no name fields were no longer submitted and all of the submitted data made it into the document in the back end. This resolution needs to be used in both Dojo 0.9 and 1.0. This was found to be a problem on R6 & R7 servers (I haven't tested on R8).
Bookmark :
Hi, David Bockes here. I've been working on a pretty extensive Dojo & Domino application. I have quite a few things that I should be blogging that have come out of this project that may be of interest, however I have been lax to do so. But, I'm going to try and correct that now. So, let's start with an issue that came up when trying to post a form back to the Domino server using xhrPost to save through Ajax.
I noticed that I would get inconsistant save results and that sometimes all the data in the form would save correctly and sometimes it would cutoff the data at a certain point. I then found that this would be based on whether or not data had been entered into fields that had been set as widgets (in this case the DateTextBox widget). The field had been defined as a widget by adding the following to the html attributes:
dojoType="dijit.form.DateTextBox" constraints="{datePattern: 'dd-MM-yyyy'}" required="true" promptMessage="dd/mm/yyyy" invalidMessage="Invalid date. Use dd/mm/yyyy format."
When sent to the browser, the outputted html for this field looks like this:
input name="ir_lh_Incident_Date" value="" dojoType="dijit.form.DateTextBox" constraints="{datePattern: 'dd-MM-yyyy'}" required="true" promptMessage="dd/mm/yyyy" invalidMessage="Invalid date. Use dd/mm/yyyy format." id="ir_lh_Incident_Date"
Note that in addition to a name, I also made sure to add an id in the properties box for this field (a good best practice for your Dojo stuff). Now, when this is parsed by dojo, the resulting html looks like this:
input id="ir_lh_Incident_Date" class="" type="text" autocomplete="off" dojoattachevent="onfocus,onblur:_onMouse,onkeyup,onkeypress:_onKeyPress" dojoattachpoint="textbox,focusNode" tabindex="0" value="" aaa:valuenow="" aaa:invalid="true" aaa:disabled="false" style=""
input type="text" value="" style="display: none;" name="ir_lh_Incident_Date"
Notice that two fields are created, one only has an id and no name and is the displayed version of the field that will show the date picker when clicked on. Right beneath that is a hidden version of the field that has a name but no id. When this form is submitted, the value from the display field is placed in the hidden field and is what gets saved into our document. However, the problem with the data save problems is due to the display version of the field. Domino is looking to match up the fields based on the name, not the id. The display version has no name, just an id. Now, you'd think that this would just get ignored, but it didn't.
I attempted to correct the issue in a WebQuerySave agent both by trying to strip out the no name fields or to only get the named fields and copy those. However this, since it's kinda a buggy problem, didn't work. So instead we took the approach of preventing the no name fields from being submitted in the first place. This was done by editing the Dojo source code and recompiling the custom Dojo build that I'm using.
To fix this, we have to use a "source" version of Dojo. A source version has the code that makes up the dojo.js and dijit.js split out into individual js files. In this case, we needed to edit the dojo\_base\xhr.js file. In there is a function called "formToObject" that is called as part of the xhrPost process. This function uses a dojo query to get only form elements on the page to submit to the server, leaving behind everything else. The key line for us is:
var iq = "input:not([type=file]) :not([type=submit]) :not([type=image]) :not([type=reset]) :not([type=button]), select, textarea";
This line builds the query to be used. Notice that it contains inclusions and exclusions (i.e., :not). The fix was to change the line to:
var iq = "input:not([type=file]) :not([type=submit]) :not([type=image]) :not([type=reset]) :not([type=button])[name], select, textarea";
Notice the inclusion of "[name]". This tells the query that the required item has to have a name attribute, if not, it is to be excluded. After making this change and recompiling the custom build, the problem was resolved. The no name fields were no longer submitted and all of the submitted data made it into the document in the back end. This resolution needs to be used in both Dojo 0.9 and 1.0. This was found to be a problem on R6 & R7 servers (I haven't tested on R8).

