Hi,
How to convert alphabets which i type in textbox feild to uppercase.. Even if i type in lower case it should be converted to upper case. Is there any property to do…user should view only upper case alphabets… waiting for reply…
Hi,
How to convert alphabets which i type in textbox feild to uppercase.. Even if i type in lower case it should be converted to upper case. Is there any property to do…user should view only upper case alphabets… waiting for reply…
Use the FormItem.change() handler, and return false for any characters you don’t want to allow.
Better yet, add this to your field definitions on your form where forced uppercase is desired.
transformInput: function (f, i, v, ov) {return v.toUpperCase()}
example:
isc.DynamicForm.create({
ID:"myForm",
dataSource:"myDataSource",
fields:[
{name:"firstName",
title:"First Name",
width:100,
transformInput: function (f, i, v, ov) {return v.toUpperCase()}
},
.... more fields
]
})
Your fields you use it on will be uppercased as data is entered and it shouldn’t interfere with any validation.
An even better solution if you don’t mind processing every character entered into all fields is to use the form level change function and turn on and off uppercase for the whole form with field by field overrides as needed as shown below.
NOTE: For Dynamic Forms, the change function is called itemChange and the system calls it automatically if you have defined it for your form after every change to any item on the form. It gets called immediately following the item level change function, provided that the item level change function (if defined) did not return false.
The form level itemChange function defined as shown in the example below will force uppercase for all fields or individual fields depending on the existence of a form level field forceUpper : true or the existence of item level fields forceUpper : true
To override the form level forceUpper, use an item level allowLower : true. Using an item level forceUpper : false will not do it as a nonexistent item level forceUpper also evaluates as false without additional time consuming tests.
isc.DynamicForm.create({
ID:"myForm",
dataSource:"myDataSource",
itemChange: function(i, v) {
if ((this.forceUpper || i.forceUpper) && ! i.allowLower) {
if (ov != null) {
this.setValue(i.name, v.toUpperCase());
}
};
return true;
},
forceUpper : true, // forcing uppercase for all fields
fields:[
{name:"firstName", title:"First Name", width:100},
// next field is uppercased even if form level forceUpper is not set
{name:"lastName", title:"Last Name", width:100, forceUpper: true},
// next field is NOT forced to uppercase even if form level forceUpper is set
{name:"streetAddress", title:"Street", width:200, allowLower: true},
.... more fields
]
})
I don’t doubt but what the code might be improved upon but it does get the job done.
EDITED 08-21-2008: I discovered the code above would cause an error when you deleted all characters in a field so I changed this:
this.setValue(i.name, v.toUpperCase());
to this:
if (ov != null) {
this.setValue(i.name, v.toUpperCase());
}
It solves the problem.
Nice rodrich! That was a hell of a lot better than our own response, we have to admit!
Thanks!
I have a question for you guys though… it took me a good while to make this work because the docs for this function say:
Parameters:
.. item - type: FormItem
… the FormItem where the change event occurred
.. oldValue - type: any
… value for the FormItem had previous to this change() event
.. newValue - type: any
… new value for the FormItem
Although I suppose that what they say is technically correct, the docs as written would seem to indicate (to my mind at least) that the ‘oldvalue’ parameter has the field without the keystroke you just pushed, when in fact the ‘oldvalue’ parameter contains the value of the field with the keystroke already added and the ‘newvalue’ has the value of the field before you hit the key. It seems like your ‘oldvalue’ and ‘newvalue’ parameters are actually just the opposite to me. Anyway, this means what I end up uppercasing is actually the ‘oldvalue’ parameter in my example. I did not even bother to provide for recieving the ‘newvalue’ parameter since it doesn’t get used.
When I transform the ‘oldvalue’ parameter and write it back to the field I am overwriting the already displayed lowercase but fortunately it happens so fast it doesn’t get noticed. I assume that this event somewhere in your code gets triggered by the javascript onchange event and the field therefore is going to have the key already posted by the time that fires and thus the above behavior does makes sense. It’s more what the doc for this function seems to say that I had a problem with.
I think that the docs could perhaps be changed to clarify that the parameters passed as ‘oldvalue’ and ‘newvalue’ contain what the field is now with the keystroke already applied as ‘oldvalue’ and that ‘newvalue’ is what the field will revert to if you return false from the itemChange function call.
Hopefully I am not the only one who finds that confusing… anyway, just thought I would bring it up.
As I dig into the library more I plan to put up more tested examples of how to use the various functions available. I think the more of those we all contribute, the easier the whole library will become to use and understand for all. These forums already contain some of these solutions but I was thinking perhaps in a Wiki type deal so we could organize them in a more documentation like manner and you guys could correct entries if someones explanation of how a smartclient method works is incorrect.
Organized correctly, user contributed, tested short code examples of how to make use of a method or variable in the objects provided in smartclient would be very helpful to all of us as developers.
The docs are good but still suffer a great deal from not nearly enough examples of how to use the lower level functionality. The more documentation and examples available, the more people will use your already excellent product. Some of the stuff in the APIs needs little or no further explanation at all but usage examples would be awesome for as much of them as possible. You could make it a condition of the Wiki that what we post is free to be used by Isomorphic in future revisions of the docs. We could end up with many examples of using a function to solve some problem or other, all of which would help everyone write better code faster. You guys gave us a gift by going open source. We can use the opportunity to make it even better by contributing to the knowledge base and docs in this way. The forums are not organized in a way that makes this type of thing work best but a Wiki like approach would work pretty well. You could define a general format to help with searching it. Something like this perhaps?
Method(s) Illustrated: DynamicForm.itemChange(), FormItem.transformItem()
Problem Solved: Forcing Uppercase In Form Fields
A copy of the method call parameters doc entry could go next
Illustration and explanations of method use to solve the problem.
I would be willing to create such a place myself on a new domain as an unofficial deal but I wouldn’t want to tread on any toes with included doc fragments and such, and I think if it were here at your site, more people would be aware of it and use it.
Your thoughts?
Too bad you ran into that itemChange() issue. The parameter order is correct, but the documentation of the parameter order was incorrect in the first cut of the API in 6.0 - that was fixed for 6.5.
Definitely agree that a wider variety of detailed usage examples would be a huge help, and a wiki is the right approach to allow the community to contribute. Ultimately this would be a wiki at SmartClient.com, however, if you were to start a MediaWiki-based wiki that allows export of content (many do), that certainly would not be regarded as stepping on anyone’s toes and we would definitely endorse the effort.
In terms of searchability and naming conventions, what might be ideal is a wiki integrated with the SmartClient Reference so that the Reference could actually detect that usage examples had been posted on a public wiki for a given API. For example, if you were viewing DynamicForm.itemChange, it could ping a URL:
http://smartclient.com/publicwiki/dynamicForm.itemChange/
.. and offer a link if the page existed and had examples.
I definately need to upgrade the version I am using then if 6.5 has corrected it. I downloaded it a when it was released but have not uploaded it to the server yet. As for the wiki… I will look into the one you mentioned and talk to you more about it when I get time. I have to catch up to a few other things that are keeping me from digging into this at the moment unfortunately but I like the idea of tying it to the docs for sure! Now I just gotta find some free time…