Home › Forums › JavaScript › Working on a B-tree form.
- This topic is empty.
-
AuthorPosts
-
September 19, 2014 at 4:11 pm #183658nixnerdParticipant
Gotcha. Ok. How do you feel about keeping the next button from being clicked at all if validation is not met? What I mean is… having it set to disabled by default and then “unlocking” it when the criteria is met.
September 19, 2014 at 4:28 pm #183659__ParticipantCould. It’d just be “one of those extra touches”; you’d have to check when it was clicked anyway.
You might be interested in this sitepoint article. Some (I think most but I’m not sure) browsers have a
.willValidate
property on form inputs. Hooking into that instead of running your own validation would be fatser than JS validation (plus, less coding), assuming support for whatever you’re validating is good enough.September 20, 2014 at 9:29 am #183682nixnerdParticipantWhoa… will do. I’m going to read that right now. Sounds very intriguing.
September 20, 2014 at 9:41 am #183683nixnerdParticipantGoing back to this:
My biggest concern is that when the user moves beyond the root level… we’re setting root to display:none. Therefore, I have questions about whether or not the submit button is actually going to submit the root with the given branch. Maybe we could cache it somehow?
My fear is now the opposite. We’ll have validation rules on ALL input fields… visible or not. So, let’s say the user selects a branch based on their needs and satisfies the validation conditions for that branch… all the other branches are invalid. So, if the submit button is submitting them all… we’re going to get errors and a contact form that doesn’t work. How can we selectively submit?
September 20, 2014 at 10:15 am #183684__ParticipantSo, let’s say the user selects a branch based on their needs and satisfies the validation conditions for that branch… all the other branches are invalid.
A few possibilities come to mind:
- Validation for one branch can easily depend on another. For example:
branch:{ one:{ validation: function(){ /* validate; return true or false */; } }, two:{ validation: function(){ if( ! branch.one.validation() ){ return false; } else{ /* continue validation; return true or false */ } } } }
- when validating one branch (or, better yet, when going to the “next” branch), we could explicitly unset values on any “unavailable” branches.
-
on submission, perform one last validation which covers the whole form.
How can we selectively submit?
You may not need to. The server can decide how to validate the form based on early values, just like the front-end can. Unneeded inputs will just be ignored. You could also set an “action” value before submission as a hint at which validation approach to use.
September 20, 2014 at 10:34 am #183688nixnerdParticipant>The server can decide how to validate the form based on early values
I guess you’re right. And… there’s a back-end dev on this project so, I’ll let him worry about it. And you’re totally right about having conditional validation. I’ll worry about that when I get there.
September 20, 2014 at 1:43 pm #183700__ParticipantAs long as there’s no naming conflicts, and the back-end guys doesn’t do anything foolish, there shouldn’t be any problems.
September 20, 2014 at 1:56 pm #183702nixnerdParticipantAs long as there’s no naming conflicts, and the back-end guys doesn’t do anything foolish, there shouldn’t be any problems.
Sweet.
September 20, 2014 at 2:03 pm #183704__ParticipantAs long as there’s no naming conflicts, and the back-end guys doesn’t do anything foolish, there shouldn’t be any problems.
…says the man who will never have to deal with any of it.
Just a grain of salt. Enjoy. -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.