Val, is there a way to something along the lines of this (controller)
Where the Javascript is ONLY fired off if a certain condition is met?
Thanks ...
----------------------------------------------------------------------------------------------------------------------------------------------
def login():
print "Doing the LOGIN form ...\n"
in_form = SQLFORM.factory(
Field('userid' , requires=IS_NOT_EMPTY()),
Field('password', requires=IS_NOT_EMPTY()),
Field('rememberlogin' ),
Field('mydate', format=('%m/%d/%Y')),
Field('married' ),
formstyle='divs',
submit_button=' Submit '
)
in_form[0][-1][1][0]['_class']='button'
print "LOGIN: Doing the process form testing ...\n"
if in_form.process(session=None, formname='login').accepted:
print "LOGIN: Accepts...\n"
response.flash = 'form accepted'
redirect(URL('buttonbar'))
elif in_form.errors :
print "LOGIN: error...\n"
# Fire off the sweetalert as well if we have an error ...
response.flash = 'form has errors'
# The following will fire off the sweetalert in the view
# dict creates a dictionary:
#js_args = dict(message = "Hi There")
# The view, ASSIGNJS, creates the list for the sweetalert popup ...
print "Setting JS args...\n"
js_args = dict(topline = "Hi There",
title = "You screwed up!",
type = "error",
confirmbutton = "Really?")
print "LOGIN: RETURN Form ...\n"
return dict(form=in_form, js_args=js_args)
return dict(form=in_form)
-------------------------------------------------------------------------------------------------------------------------------------------
Again, Thanks ...
*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division
On Tue, Feb 19, 2019 at 6:48 AM Ben Duncan <[email protected]> wrote:
> WHoa HOOOO !!!!!
>
> Thanks VAl that works !!!!
>
>
> *Ben Duncan*
> DBA / Chief Software Architect
> Mississippi State Supreme Court
> Electronic Filing Division
>
>
> On Fri, Feb 15, 2019 at 2:39 PM Val K <[email protected]> wrote:
>
>>
>> include arguments (that it should be json-serializable object) to pass to
>> js-code in the controller output:
>>
>> # controller.py
>> def foo():
>> ...
>> js_args = dict(message = 'Hi there!')
>> return dict(..., js_args = js_args)
>>
>>
>> insert script into your view
>>
>>
>> <script type = "text/javascript">
>> $(document).ready(
>> function(){
>> {{=ASSIGNJS(args = js_args)}} // - converts js_args to `var
>> args = {"message": "Hi there!"};`
>> Swal.fire(args.message);;
>> }
>> )
>> </script>
>>
>>
>>
>>
>> --
>> 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 [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.