Hi
I have a requirement to restrict a ZIP code to a 5 digit number. After entering the required 5 numbers, the user can keep pressing any other number or any other character on the keyboard (a,b,x, d.....), but no input is to be allowed. In short, the user will be typing nothing. The below Javascript/XHTML will accomplish the behaviour I am looking for, but the question is: how can I implement the same in XForms. <SCRIPT TYPE="text/javascript"> <!-- // copyright 1999 Idocs, Inc. http://www.idocs.com // Distribute this script freely but keep this notice in place function numbersonly(myfield, e, dec) { var key; var keychar; if (window.event) key = window.event.keyCode; else if (e) key = e.which; else return true; keychar = String.fromCharCode(key); // control keys if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) return true; // numbers else if ((("0123456789").indexOf(keychar) > -1)) return true; // decimal point jump else if (dec && (keychar == ".")) { myfield.form.elements[dec].focus(); return false; } else return false; } //--> </SCRIPT> Now we can create a numbers only field using the onKeyPress attribute. For our first example, we'll create a field which accepts five digits as for a United States ZIP Code. Set the onKeyPress attribute exactly like it is here: <FORM ACTION="../cgi-bin/mycgi.pl" METHOD=POST> U.S. ZIP Code: <INPUT NAME="dollar" SIZE=5 MAXLENGTH=5 onKeyPress="return numbersonly(this, event)"> <INPUT TYPE=SUBMIT VALUE="go"> </FORM> --------- How can I achieve the same with XForms. Right now, if I enter 95928 in the ZIP code and continue typing abcd1234..the field will continue to take these characters. How can I restrict this to 95928 or 17110 and stop at that? thanks ilango |
hi ilango,
wouldn't it be much easier to restrict the input using a binding constraint (either using a regex or a xs:type and maximum length)? Additionally, you could use the xxforms:maxlength attribute if your control is a xforms:input field. HTH florian -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Hi Florian
I did have a regex in my bind as follows: For example, instead of a Zip code, I want to have a three digit field, where I would like to restrict my input to a 3 digit number between 000 and 772. <xforms:bind nodeset="instance('taskoutput')/fe:datafe:part1" id="test1" type="xs:integer" constraint="matches(.,'^\d{5}([\-]\d{4})?$)') and (string-length(.) = 5)"/> and also: <xforms:input ref="instance('taskoutput')/fe:data/fe:part1" bind="test1" incremental="true" id="firstThreeDigitPart" maxlength="5"> It does not seem to work. any suggestions are appreciated ilango
|
In reply to this post by fl.schmitt(ops-users)
Well, I applied this method to aan SSN field.
I expect the following behaviour. I type in the first field of SSN as a three digit number and because of xforms:maxLength=3 it will not let me type anything else in this field. For example, if I type in 123 in the first input field box and then I type in 4 (and there is this second input field box beside the first one with the appropriate - betweeen them ), the 4 should automatically be typed in the second box. But right now this does not happen. Any suggestions on how I can make this work. I tried both the following binds: <xforms:bind nodeset="instance('taskoutput')/fe:SSN/fe:part1" id="test1" type="xs:integer" constraint="matches(.,'^([0-6]\d{2}|7[0-6]\d|77[0-2])') and (string-length(.) = 3)"/>
|
Administrator
|
On Thu, May 15, 2008 at 7:03 AM, ilango_g <[hidden email]> wrote:
> For example, if I type in 123 in the first input field box and then I type > in 4 (and there is this second input field box beside the first one with the > appropriate - betweeen them ), the 4 should automatically be typed in the > second box. You could: * Add incremental="true" on the field. * On xforms-value-changed, check if the length of the next in the field is 3; if this is the case, set the focus on the next field. Alex -- Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise Orbeon's Blog: http://www.orbeon.com/blog/ Personal Blog: http://avernet.blogspot.com/ Twitter - http://twitter.com/avernet -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Actually I did get the functionality working in FormsPlayer. It seems to me that the "xforms-valid" event that I use for setting a setfocus does not fire for some reason.
And in my original example, I do have an incremental="true". I have a simple example here, that can be tested in the sandbox. This shows the problems I have been having. And this is what I already had in my code: <xforms:action ev:event="xforms-value-changed"> <xforms:setvalue ref="instance('taskoutput')/fe:SSN/fe:part1_final" value="substring(instance('taskoutput')/fe:SSN/fe:part1,4,1)"/> </xforms:action> <xforms:setfocus ev:event="xforms-value-changed" control="secondTwoDigitPart" if="string-length(.) eq 3 and . > 0"/> <xforms:label>Arrestee SSN: </xforms:label> Should I enclose the setfocus inside the value-changed-event action body? view.xhtml ilango
|
Actually, my original message should have included the information that when I got the functionality working in FormsPlayer (different from the code attached), I tried to replicate the same in Orbeon and it did not work. Should I enclose the formsplayer sample as well for greater clarity?
|
In reply to this post by ilango_g
hi ilan,
> http://www.nabble.com/file/p17293727/view.xhtml view.xhtml your example file works fine in the online sandbox when changing the bind constraint in line 56 from (string-length(.) = 4) to (string-length(.) = 3) and the if condition in line 88 from string-length(.) eq 2 to string-length(.) eq 3 HTH florian -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Hi Florian
That is great! Are you able to type in: 123456789 in continual fashion without interrupting the flow of digits? Well, I tried your changes. I try to type in: 123456789 in a continual fashion, without pause. I find that I am not able to get 4 typed in.The 4 will get typed in, but only if I pause and allow a small timeframe, the 4 gets typed in though. 5 will get typed in if I do not allow this timelag. There seems to be a slight lag when the cursor jumps from one box to the next. Now if I shorten the field length to just accommodate the SSN fields, will the timelag go away. For example, the below example (Tested with Formsplayer) shows the effect I am looking for. ssn-xforms-2.html
|
hi ilan,
> Now if I shorten the field length to just accommodate the SSN fields, will > the timelag go away. i fear it won't - i think this is due to the client-server/AJAX architecture. i see two possible solutions: - accept the lag - the user will have to wait a little, and because of the validation, he is forced to do so. - use only one input field for the complete SSN and split the value entered using the substring funtion - this could be done incrementally. You could add three output fields, one for each SSN part that are updated with every keystroke. HTH florian -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Ah, I suspected that.
Now, regarding the lag: - use only one input field for the complete SSN and split the value entered using the substring funtion - this could be done incrementally. You could add three output fields, one for each SSN part that are updated with every keystroke. Could you elaborate on this further? Does this mean that the user types in all the 9 digits of the SSN continuously. ilango
|
hi ilan,
> - use only one input field for the complete SSN and split the value entered > using the substring funtion - this could be done incrementally. You could > add > three output fields, one for each SSN part that are updated with every > keystroke. > Could you elaborate on this further? > Does this mean that the user types in all the 9 digits of the SSN > continuously. yes, that's possible. I've attached a simple example (had to modify the regex a little because negative look behind seems not to be supported). There's only one input field for the complete SSN. Beneath, there are three xforms:output fields that will display the parts separated by the SSN separator. The model contains a setvalue to initialize the SSN from taskinput. The SSN parts in taskoutput are calculated from the complete SSN by a substring function. There's still a little lag between the keystrokes when entering the SSN and the output of its parts, by the user can type continuously, and no keystrokes are "lost". Of course, the example could be amended, for example to apply the substring function only if there's enough data entered to split. HTH florian -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws view.xhtml (6K) Download Attachment |
Hi Florian
I tested your form and it works well. It addresses key concerns nicely. Now as a final step I would like to add another feature (or an embellishment perhaps?),which I think will make it more intuitive My original idea about the 3 boxes was to have this intuitive 3-part SSN field that the user will readily recognize. In that design I added in those 3 boxes and inserted that "-" to prevent the user from having to type in that character. Now, I would like to enhance your design to accomodate these features: My ideas are: 1) Insert an image over the single input field that appears to the user as three separate field. This would be another input image field sitting in place of the existing input control with the exception that there are 2 thin dividers. Or have an image with the spaces in it. 2) Alternatively, automatically have the system type in an "-" after he/she types in the first three characters of the SSN and another "-" after the next two characters. I know these are embellishments, but I would like to try one of these. What do you think is a preferred approach for that desired user experience? thanks ilango
|
ilango_g schrieb:
> My ideas are: > 1) Insert an image over the single input field that appears to the user as > three separate field. This would be another input image field sitting in > place of the existing input control with the exception that there are 2 thin > dividers. Or have an image with the spaces in it. > 2) Alternatively, automatically have the system type in an "-" after he/she > types in the first three characters of the SSN and another "-" after the > next two characters. > > I know these are embellishments, but I would like to try one of these. > What do you think is a preferred approach for that desired user experience? possible, too - some people modified / replaced the slider control with one showing values / numbers. But in your case, the numbers entered would have to fit exactly in the space left by the overlay, and that's quite tricky, i think. That solution depends on certain layout preferences which may vary from user to user and from browser to browser. So, i think the second alternative is the only one that could work. For the second alternative: When modifying the field value while the user enters the SSN, we may run again into the problem regarding the little lag. It would require to check the actual value and to issue a setvalue to insert the divider. If the user continues to enter numbers, they may get lost during that process. So, i fear a secure solution would be to wait until the user has entered the complete SSN, or even the field has lost the focus. But this may not be the desired user experience. Another alternative may be to use a completely different approach: how about creating a little java applet that would allow to enter the SSN as you desire? This is a quite costly way, of course... florian -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
I am afraid you are right about my alternatives.
1)What do you feel are the advantages of a Java applet 2) Do you think the applet is costly because of the performance overhead involved? 3) Another alternative I came up with is as follows: Use the following Javascript code available at: http://www.htmlcodetutorial.com/forms/index_famsupp_162.html - inside my XForm. Again, I might be naive about this one. Do you think I might still have the timelag if I used the above Javascript and I reference the Javascript for my control inside the form? thanks ilango
|
hi ilango,
> 1)What do you feel are the advantages of a Java applet It doesn't have to communicate with the server while the user enters the data, so the risk of a network lag is smaller (not existent??). > 2) Do you think the applet is costly because of the performance overhead > involved? This is one point - it involves additional technologies and adds complexity to the whole system. Leaving the field of "pure XForms" may decrease portability. I'm not sure whether it may cause new problems regarding different browser environments. > 3) Another alternative I came up with is as follows: > Use the following Javascript code available at: > http://www.htmlcodetutorial.com/forms/index_famsupp_162.html - inside my > XForm. > Again, I might be naive about this one. Do you think I might still have the > timelag if I used the above Javascript and I reference the Javascript for my > control inside the form? I'm not sure - i suppose what matters is that if the focus is moved, the browser will communicate with the server to update the model (i don't know about the client-server communication en detail). So, it doesn't matter _how_ the focus is moved, it matters _that_ the focus was moved. As long as there are multiple xforms control and the user moves from one to another, the problem will stay, i fear. Maybe it works with simple form fields: you could try to nest a xhtml form into the xforms page and use javascript to read out the values entered. I coulnd't test this because the online xforms sandbox seems to filter out embedded Javascript. florian -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Hi Florian
I am not against the idea of using a Java applet here. This sounds like an option I could use. Then your latest alternative, -> the use of an XHTML form embedded inside XForms: I want to try this one out first before going in for the applet. ilango
|
Free forum by Nabble | Edit this page |