Thinking about abusing the jQuery Validate plugin...


  • Impossible Mission Players - A

    So I have a page that uses jQuery Validate For All Your Validation Needs™, but now we're thinking of doing something that may theoretically be possible, but introduces quite a bit of undefined sludge to the mix.

    Background: This is a questionnaire system that users submit data to. Later on in the process, if the answers aren't "satisfactory", a "remediation team" goes in, fixes the problem that generated the unsatisfactory answer, and marks it as such in a "remediation page". Now, the consumers want to be able to "pre-remediate" the initial submission, i.e., they know this is a bad answer, but want to click the "I fixed this" box right there in the form as they're filling it out (yes I know this is a terrible idea, no I haven't yet gotten them to budge on it).

    Anyways, so I'm thinking of how to do this, and it seems easiest to dynamically add in a checkbox element (or whatever) to the form next to the input whenever that particular answer gets an "unsatisfactory" value in it, so they can check it and move on.
    The problem is that I don't want to try implementing my own version of jQuery Validation, and I'm not sure how to separate actual "Validation failed" statuses with "Well, validation failed so the plugin would generate an error element which we re-wrote to actually slice in a new Input element and friends, so it failed once but now all the sudden it's not a fail".

    Am I off my rocker, is this even possible?

    The end goal is to have one set of validation rules to do the actual validation and marking-errors bit, and one set of rules to appear/disappear the "we know this is bad, but we fixed it" input element.



  • So, right now:
    The answer is bad, user gets a validation error and is stuck until corrected.

    You want:
    The answer is bad, user gets validation error, but also a checkbox. If checkbox is checked, error disappears and user can move on as if the answer is correct.

    Right?


  • Impossible Mission Players - A

    @cartman82 said:

    Right?
    Basically. Although, slight modification: if it's bad, and they don't check the box, it still gets submitted (i.e. form is "valid") and gets handled the normal way (the "remediation group" uses their version of the form to mark it fixed).



  • I don't understand.

    Sounds like the form is submitted whether the answer is good or bad. And whatever processing you do afterwards (including these remediation groups) has nothint to do with jquerry validation.



  • Am I reading this right, you want

    • Good, submits ok
    • Bad but box ticked, submits ok and fixed by an internal team
    • Bad but box unticked, submits ok and fixed by an internal team?

    It seems like you want to remove the client side validation, and just have server side logic that sets a flag for your internal team to check it?


  • Impossible Mission Players - A

    @cartman82 said:

    Sounds like the form is submitted whether the answer is good or bad. And whatever processing you do afterwards (including these remediation groups) has nothint to do with jquerry validation

    Kinda. Yes, the form gets submitted, but essentially I'm adding part of the functionality of another form (the marking "this is fixed" part) to the this one.

    @Nocha said:

    Am I reading this right, you want

    • Good, submits ok
    • Bad but box ticked, submits ok and fixed by an internal team
    • Bad but box unticked, submits ok and fixed by an internal team?

    It seems like you want to remove the client side validation, and just have server side logic that sets a flag for your internal team to check it?


    #2 is more like "Bad, but box appears and gets ticked, no interaction by remediation team"
    #3 is like "Bad, but box appears and doesn't get ticked, interaction needed by remediation team business as usual"

    The apparent idea is to give the first answers the chance to be remediated before needing remediation by the remediation team. Essentially, it skips the bucket if they tick the box here.



  • What happens if the user enters bad information and ticks the box avoiding the remediation team? How will later systems cope with being fed garbage data? This sounds like a recipe for disaster...


  • Impossible Mission Players - A

    The more I evaluate this, the more it sounds like hacking a really ugly bodge into the Validation plugin.

    Current plan goes as follows:

    • For those questions that have a remediation condition (aka bad value rule), add a validation rule that checks the condition, and also checks if there's an extra sub-element containing the "this is fixed" box. If it passes, or the box is there, validation is good. Additionally, set a custom message that's an encoded string for the next part.
    • In the errorPlacement handler, check if the error message is in the previously mentioned format, and if so:
    • Drop the Validation Plugin's version of the error element, and build up a custom one (being careful to avoid giving it an ID of [name]-error).
    • re-trigger validation, but only for that particular field.
    • Figure out if doing this will ostracise the new element from the Validation Plugin's handling (because we want the new element to disappear/become erased if the value is replaced with something not a "bad value), and if so, attach an event handler to the source element

    @Nocha said:

    What happens if the user enters bad information and ticks the box avoiding the remediation team? How will later systems cope with being fed garbage data? This sounds like a recipe for disaster...

    For the moment, it's "I don't care" from the customer. I'm still working on getting them to see reason, after all. 😉
    Apparently, they'd rather have users intentionally entering bad data and claiming it's been fixed, than having another set of eyes actually verifying it's been fixed.



  • So your current form uses jquery validate to notify users of answers that don't match the rule, but doesn't prevent them from submitting, and you want to change it to notify users of answers that don't match the rule and add an extra input element to let them indicate whether the question will need to be revisited and still not prevent them from submitting? I don't see any problems there.


  • Impossible Mission Players - A

    @Buddy said:

    So your current form uses jquery validate to notify users of answers that don't match the rule, but doesn't prevent them from submitting,

    Not quite, we prevent submission if the "normal" validations fail, but not if the "needs remediation" rules fail. In other words, multiple validation.

    @Buddy said:

    and you want to change it to notify users of answers that don't match the rule and add an extra input element to let them indicate whether the question will need to be revisited and still not prevent them from submitting?

    Not quite. The idea is that they can check a box that indicates that they fixed the issue that caused the "needs remediation" rule to fail.

    As an example, say I have a question, and it's a free-form text box asking for a number. If the number is above a given value (say, 50), it's still a valid entry, but requires remediation. Therefore, there will be two rules:

    1. Is the input given a number? (If no, fail validation, prevent submission)
    2. Is the input given > 50? (If no, don't do anything, if yes, show a checkbox, submission can succeed so long as #1 is good)

    So, if they put in 51 as the answer, it's Ok to submit, but they have the opportunity and option to check the box that says "I fixed this", which allows things further down the line to be skipped.
    If they put some gibberish, they couldn't submit it, and rule #2 wouldn't apply at all because #1 failed.



  • Ok, I'm not sure I'd call that multiple validation then. I'd say that part 1 is a validation step, and part 2 is changing the form based on the value of already validated data.

    I'm not front end, but the way I would expect this to be done is to have the checkboxes always present on the form, but hidden, with a data element relating them to the question, then put a hook on validation success that unhides them as appropriate.


  • Impossible Mission Players - A

    @Buddy said:

    have the checkboxes always present on the form, but hidden, with a data element relating them to the question, then put a hook on validation success that unhides them as appropriate.

    This was one of the ideas, but then I would be writing my own rules engine. 😊
    It sounds like that's probably going to be the way to go, since I'm not really liking the way I would need to abuse the Validation Plugin...


  • I survived the hour long Uno hand

    I think you're using what should be basic validation (did they enter anything, did they put letters in a number field) to do business logic, which it's not designed for.


  • Impossible Mission Players - A

    @Yamikuronue said:

    it's not designed for.

    Yeah, that's probably why it's so difficult....


  • I survived the hour long Uno hand

    If I've learned one thing from the project I'm on right now, it's that you definitely need to clearly separate basic validation from business rules.

    But don't do it the way we're doing it, our business rules handling is pants-on-head stupid. You want a single, concise location for your business rules.


  • Impossible Mission Players - A

    @Yamikuronue said:

    You want a single, concise location for your business rules.

    In this case, I have two tables total, validation and remediation, of which a given question can have one of each. So, at least there's that...



  • My current thinking is I would use the jquery-dependent-questions plugin, just extend it to allow properties of the form data-depends-on="functionName(inputName), where functionName is looked up in a dictionary somewhere, like functionTable[name](value).



  • @cartman82 said:

    You want:The answer is bad, user gets validation error, but also a checkbox. If checkbox is checked, error disappears and user can move on as if the answer is correct.

    Right?

    It seems like you can just uninstall the validation if the checkbox is checked. I'm not sure how to uninstall the validation in that library, but... isn't it as easy as that?


  • I survived the hour long Uno hand

    The quoted assumption is wrong, I think. From what I can tell, if its like what we're doing, it's not that you want the user to be prevented from moving on, but instead, you want to take different actions on the backend depending on if their answers met certain rules. It's just confusing because one set of rules defines a 'bad' answer, which needs to go into the 'bad answer' flow.

    @Tsaukpaetra said:

    "Bad, but box appears and doesn't get ticked, interaction needed by remediation team business as usual"

    isn't the usual "pop up a red box and make the user fix their error" flow that you'd want for things like, they typed "banana" into the "phone number" field.



  • Yeah I answered too early. I don't really get this in a couple ways.

    Why is the front-end and not the back-end the determinator of what constitutes a "bad" answer? Does the back-end just trust the front-end's opinion? Or...? Front-end validation is supposed to be a convenience to save the user time, not the authoritative source of validation.

    And like you said, what we're doing here is really almost entirely unrelated to validation. (It's kind of the opposite of validation, really.) So. It's not surprising that a validation library doesn't support it.

    It seems to me that the "correct" way of doing this would be to do the normal validation on the back end, and then the back end redirects to a page saying something like, "your data is bad because X, Y, Z, are you sure this is correct?" with a yes/no button.

    Think about how when you enter an incomplete address to, say, Amazon, and they come back with, "is this the ZIP+4 you intended?"

    But anyway, the real problem here is a user problem. The person entering the data is always going to say they did it right, and therefore there's no point in the remediation process existing anymore. Assuming there was a reason the remediation process existed in the first place, you're almost certainly throwing some babies out with that bath water.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.