Restricting Field Input to 160 Characters

Questions and answers for designing and implementing forms in Servoy

Restricting Field Input to 160 Characters

Postby dpearce » Sun Mar 18, 2012 1:09 pm

I am using a global field to input an SMS message in a text area.

Is there anyway I can restrict the input without have to click out of the field to 160 characters.

I have tried the format of the field, but that doesn't seem to work using AAAAAA 160 times.

Is there anyway to define the global variable to restrict its size to 160 characters?

Obviously one could use an on oculist or data changed, but that would only work when clicking out of the field.

David
dpearce
 
Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Re: Restricting Field Input to 160 Characters

Postby ROCLASI » Sun Mar 18, 2012 2:20 pm

Hi David,

If you use SmartClient you could use the KeyListeners plugin for this. You can define a callback method on this field and make it return true or false to allow/disallow new characters to be typed (make sure you allow for delete/backspace/arrow keys/etc.).
If you use Webclient you could use the WebClientUtils plugin to inject a hook to a client-side JavaScript that handles this for you.

Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Restricting Field Input to 160 Characters

Postby studiomiazzo » Sun Mar 18, 2012 11:15 pm

I used the format property in the designer to achieve this, i.e. I set the format of the field I want to constrai nt to something like '*****' with as many stars as needed. Not elegant but that's the only working solution I could come up with. However you could try assigning a checkLength method to your field's onDataChange event that checks for the content length, and in case reset the associated dataprovider to the allowed number of characters.

EDIT: are you sure the event is triggered only when the field losts its focus?
User avatar
studiomiazzo
 
Posts: 124
Joined: Thu Jun 16, 2011 10:48 am
Location: Novara (IT)

Re: Restricting Field Input to 160 Characters

Postby jcompagner » Tue Mar 20, 2012 10:25 am

or don't use a global field but a table field for this one, that has the 160 char length limit

Currently we don't support a max length through the designer (through the formatter or its own property) you can make a feature request for this.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Forms

Who is online

Users browsing this forum: No registered users and 3 guests