Well, this idea works... basically. But I need to change the DIV enclosing my "warning" message from class "error" to "warning" to get my preferred yellow color. Now here's where it gets interesting...
I can change the div using jQuery on the view. BUT that still shows me a "flash" of red before the box turns to yellow. No problem, I thought, I'll use web2py "elements" to do the change before the page is rendered. NOPE! In a bizarre twist, the DIV containing the error block is never rendered until the last possible moment -- during the "xml" method. Which means, there is no point at which you can use "elements" on the form to find the error DIV because it doesn't exist yet! There is nothing "wrong" with any of this. Every design choice is a compromise at some level. This is just the unfortunate collision of design choices to limit the usefulness of "elements" in this one corner case. The red flash isn't that bad. I'll just say I'm doing it deliberately to get the user's attention. "A feature is a bug as described by Marketing..." On Wednesday, August 22, 2018 at 4:09:49 PM UTC-7, Joe Barnhart wrote: > > I hate to answer my own post, but what if I did something in a customer > Validator? What if the error returned by my validator was something like > SPAN("blah blah", _class="warning"). Presumably I could search the FORM > using elements() finding my SPANs and then modify the enclosing DIVs to be > class "warning" also. I'd provide different CSS for the yellow background. > Just thinking out loud here. > > On Wednesday, August 22, 2018 at 3:31:14 PM UTC-7, Joe Barnhart wrote: >> >> I'm looking to add "warnings" to forms using (/hijacking) as much of the >> existing form "errors" mechanism as possible. The idea is to provide a >> second level check that gives advice rather than drop-dead errors. >> >> I would like it to operate like this: >> >> 1. The form is submitted and checked for errors as usual. >> >> 2. After the error check another set of criteria, "warnings", are >> checked. Where the errors are added as red elements below the fields, I'd >> like these to be added in yellow to delineate the difference. >> >> 3. The user gets a chance to fix the errors and warnings (as in standard >> practice). >> >> 4. If the error check passes but there are still warnings, the warnings >> are displayed. >> >> 5. Whatever the user submits after the "warnings only" check is accepted. >> >> I can figure out the two-phase form submit. I was having a little >> difficulty trying to imagine how to hijack the error message code that adds >> the error wrapper. Currently that's done in the xml method for the INPUT, >> for example, and I don't see an easy way to extend that without subclassing >> each of the controls and adding my stuff. Even then, the Fields and such >> would want to add the original INPUT and not my subclassed version, leading >> to more fun and hilarity. >> >> Any simple ideas from the web2py blackbelts? I'm a brownbelt and can >> probably implement it if you give me a hint. >> >> -- Joe >> >> P.S. An example of a warning would be if a user fills in his parent's >> last name as his first name. It's possible, but much more likely they just >> switched the first name / last name fields. (Happens a lot, for some >> reason.) >> >> -- 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.