Nice code but what I meant to say is that allowing the user to add a
new option is basically the same as saying accept anything but empty
(unless you have a list of all fruits somewhere).
Just changing the validator to IS_NOT_EMPTY would do.

On Jan 22, 2:02 pm, mdipierro <[email protected]> wrote:
> something like this?
>
> <script>
> jQuery(document).ready(function(){
>   jQuery('#mySelect').change(function(){
>     if(jQuery('#mySelect').val()=='Specify...')
>       var newoption  = prompt("Your choice:","");
>       var d = jQuery.json({url:'{{=URL
> (r=request,f='register_new_option')}}',data:'option='+escape
> (newoption)});
>       if(d['id'])
>       jQuery('#mySelect').prepend('<option>' + newoption + '</
> option>');
>       else alert(d['error']);
>   });
>
> });
>
> and create a new action in default.py
>
> @auth.requires_login()
> def register_new_option():
>      from serializer import json
>      (value,error) = db.optiontable.optionvalue.requires
> (request.vars.option)
>      if not error:
>          return json(dict(id=db.optiontable.insert(optionvalue=value)
>      else:
>          return json(dict(id=0,error=error))
>
> On Jan 22, 12:31 pm, DenesL <[email protected]> wrote:
>
> > How would you validate the field?.

-- 
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.

Reply via email to