I am pretty sure jquery.ui have client slide validators, although I never used them.
On Nov 12, 11:39 pm, Richard <[email protected]> wrote: > that sounds like an awesome reuse of the existing SQLFORM > functionality, and would be nice to see live form checks before > pressing submit. > > You do an AJAX call whenever the text box changes - wouldn't that > produce too many calls? > > Richard > > On Nov 13, 1:35 pm, Thadeus Burgess <[email protected]> wrote: > > > It is possible to use the web2py validators and javascript (AJAX). Post the > > data to the server, and then return an msg that tells details about the > > code. This way, a user can look to see if anything is wrong (if javascript > > is enabled), and the form will still be validated on post, so you don't lose > > any security. > > > Basically, I actually use the web2py validators to validate the data. > > Whenever the content of a text box changes, I use javascript to post the > > name of the field, and value to the server using AJAX. Web2py then accesses > > the field in SQLFORM, and runs the data through validation, and returns with > > the response (errorcode/ etc). > > > The only requirement is your SQLFORM variable will need to be outside all of > > your actions at the top of the file. > > > I can post some code, however I use a python javascript library I am working > > on to make some things easy. > > (py2jquery,http://hg.thadeusb.com/public/.r/Web/py2jquery/) > > > def validate_ajax(field): > > callback = Call(callback=validate, args=[field], data="input[name='%s']" > > % field, request=request) > > event = Event("change", "no_table_%s" % field, callback) > > manager.add(event, True) > > > def validate(): > > field = request.args(0) > > value = None > > for var, val in request.post_vars.items(): > > value = val > > > if isinstance(value, str): > > if field == 'name': > > value = value.capitalize() > > if field == 'email': > > value = value.lower() > > > (value, error) = signup_form.table[field].validate(value) > > if error is None: > > return signup_form_clear(field) # this returns jquery string that > > gets evaled on the client side. All this does is reset the css to default > > and clear the error message > > else: > > return signup_form_error(field, error) # this returns a jquery > > string that gets evaled and that will replace the backgroudn to red, and > > place the erro rmessage after the input. > > > def signup(): > > no_ajax = ('dob', 'state', ....etc...) > > for field in signup_form.fields: > > if field not in no_ajax: > > validate_ajax(field) > > > -Thadeus > > > On Thu, Nov 12, 2009 at 8:14 PM, Richard <[email protected]> wrote: > > > > Hello, > > > > I was wondering if it would be possible/practical for SQLFORM to > > > support some basic client side checks before submitting to the > > > server. > > > > SQLFORM has so many features, which I doubt could all be covered > > > client side, but it would make forms more responsive if atleast a > > > subset was. > > > > Richard > > > > (My particular use case is an upload form with a text field that > > > requires input of a minimum length. If the user doesn't enter enough > > > text then the form is submitted to the server before coming back with > > > an error message. The user then needs to reselect their upload file > > > because this is not saved.) > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

