On Friday, August 5, 2016 at 12:28:44 PM UTC-4, Bernardo Leon wrote: > > Hi, I have an SQLFORM.grid form and when I am inserting data I want to > make the selectors work in cascade. I have seen some recipies where they > create by hand the form using plain html and throw some jQuery in the > middle but I dont like it, I like the cleaness of web2py so I am looking > for a cleaner way to accomplish this. > > So far I am trying with ajax request and I have been able to call a > function in my controller passing the id of the parent selector to finally > change the child's selector IS_IN_DB validator. That was my idea, but it > seems I cannot change the validator from de controller, only from the > model; so is there a way to reload the model within an ajax request so I > can change the behavior of my form at runtime? Is there a better/cleaner > way to accomplish this? >
First, note that the model file is re-executed on every request, so indeed it does "reload" when you make an Ajax request. The problem is, your model includes no logic to change the validator when the Ajax request is made. You could add such logic, perhaps by sending some flag with the Ajax request, or simply setting the alternative validator whenever request.ajax == True. However, there is no need to make the change in the model file where the table is initially defined, as you can change the validators for a given field at any point in your code, such as in the controller. So, in the controller that handles the Ajax request, you could do: db.mytable.myfield.requires = new_validator Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.