-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issues on previous-step #57
Comments
About the issueIn the docs, it's like this:
So About the events and validationsYes, you're right, now the events are triggered independent from the transitions, but this shouldn't be an issue. There are several ways to add both general validation (for all steps) and custom validations (for each one): You can add a general validation function (that runs everytime the method var generalValidationFunction = function(stepperForm, activeStepContent) {
// You can use the 'stepperForm' to valide the whole form around the stepper:
someValidationPlugin(stepperForm);
// Or you can do something with just the activeStepContent
someValidationPlugin(activeStepContent);
// Return true or false to proceed or show an error
return true;
}
var stepper = document.querySelector('.stepper');
var stepperInstace = new MStepper(stepper, { validationFunction: generalValidationFunction }) Or, for custom steps validations, you can use the feedback functions themselves. The feedback functions are called with three parameters: <button class="waves-effect waves-dark btn next-step" data-feedback="customValidation">CONTINUE</button>
<script>
function customValidation(destroyFeedback, form, activeStepContent) {
// Do your stuff here like:
form.validate(function(validation) {
// Call destroyFeedback() function when you're done
// The true parameter will proceed to the next step besides destroying the preloader
if(validation) return destroyFeedback(true);
return destroyFeedback();
})
}
</script> Just a tipBy taking a look at your code, I can see you're adding methods to the Like, you're defining a method called Also, I guess you're trying to create a workaround for the events not being triggered at the end of the transitions with some extra methods, but as I explained above, I believe it's not neccessary. Well, I don't know your objectives, but maybe you really need to edit all those things, but maybe there's a better way. I'm just trying to help :) ConclusionI'll keep this open for now, since I feel you maybe have some questions yet. Thanks for using MStepper :) |
Thanks for detailed explanation. I appreciate. The validationFunction should return true or false. How do I use it with Promise, for responses from the server for example? That's the reason why I'm trying to use data-feedback. Do we need a promise version? I like MStepper. Thanks much for your contribution to the world. |
Yeah, the promise inside validationFunction is a problem. I'll be doing some tests and edit this answer asap, but in the next version I'll change it to something that works with promises. Also, I'm thinking about adding a default validation to the steps (if none is passed to the option). --- EDIT --- @HIRANO-Satoshi If it waits for a promise, a loader should be displayed, and this is not the intention of the general If you need to do async validations (like checking db), you should use feedback functions, yeah. However, I believe you still doesn't need to add a method and bind it to the |
(I've updated the above answer) |
I see. We need to wait for the result of validation anyway regardless the response is quick or slow before going to the next step. One of typical usages is to confirm the server whether email address is unique or not in the signup process. Use of data-feedback for validation is not good as you pointed out. Some people might use both validationFunction and data-feedback according to sync or async and be confused. Validation is validation. So would |
When I said "fast" or "slow", I meant sync or async. A sync task is usually faster (in a UX pov) than an async one, if it's not, it should be async instead. A simple validation (such as jQuery validation plugin or the browser's native one) is always sync and instantaneous. If In the versions 1.x.x and 2.x.x, there was an integration with jQuery validation plugin, but it was removed due to the removing of jQuery from the project's dependencies. However, there a lot of validation libs out there, and that's why I added It's 100% ok to use However, you're about people getting confused. I should've made explicit that the --- EDIT --- Maybe a more clear and short explanation would be that the |
Thanks. I can understand you. Users need explanation and one ore more examples. I as a user think Both sync and async validations are needed anyway. Users could do sync validations first for fast response and async validations later in it if they like to do so.
EDIT: Or, it could be a Promise only API. Promise is not slow actually if you return Promise.resolve().
|
But async functions are usually used to contact the database. Using your example, why would users want to
|
I see. validationFunction is a global one, while data-feedback is per step one. Sorry, my promise example was too simplified. I supposed to change validators each step, as I showed at stepChanged() in my example above. I understood that data-feedback is a way to do so. But I'm a bit confused. I don't make sense a global validation function could work for all steps, because inputs are blank in the future steps. And I think each step should have a validation function. Maybe what I need is an API that enables a step validator when step changes. Note: our app is a single page app (SPA) using Aurelia-validation |
So, the flow I had in mind when I refactored the MStepper was: Simple global input validation: var generalValidationFunction = function(stepperForm, activeStepContent) {
// Simple client-side validation for the form to work like it was outside the stepper
return activeStepContent.areTheRequiredInputsFilled()
}
var stepper = document.querySelector('.stepper');
var stepperInstace = new MStepper(stepper, { validationFunction: generalValidationFunction }) This function would run every time you hit a That's why it doesn't support async, cause it should be a simple function that do a simple validation. Like, let's suppose you're asking for a password in a step, the user's name in the other and the user's phone number in the other. All of them are required, so you have 3 steps with the same "kind" of validation, that is: "check if the required inputs are filled before proceeding to the next step". That's where If you make a simple form with no JS involved, and you try to submit the form with a required input empty, the browser's gonna stop you from submitting and show a balloon saying "This field is required". Since the stepper is fully controlled by JS, the Validation per step, maybe async: <ul class="stepper linear">
<li class="step active">
<div class="step-title waves-effect">E-mail</div>
<div class="step-content">
<input type="email" id="email_input" required>
<div class="step-actions">
<button class="waves-effect waves-dark btn next-step" data-feedback="checkEmailDB">CONTINUE</button>
</div>
</div>
</li>
</ul>
<script>
function checkEmailDB(destroyFeedback, form, activeStepContent) {
// Get the email the user is trying to use in the active step while a preloader is spinning
var email = activeStepContent.getElementById('email_input');
// Use a function to call your DB
checkInDbIfEmailExist(email, function(exist){
// If it exists, return the destroyFeedback to destroy the preloader
// The true parameter will also skip the step so like "ok, email doesn't exist, proceed"
if(exist) return destroyFeedback(true);
// Otherwise, destroy the preloader but doesn't proceed to the next one
return destroyFeedback();
// If you want, call wrongStep to show an error
// Maybe I'll add this to destroyFeedback native working flow
stepperInstace.wrongStep();
});
}
</script> This way, the If you need to validate another step, create another function and bind it to the ---EDIT--- Oh, I got your doubt. The |
Updated answer! |
I visited your HP. It's nice. If you intended to validate each step with one We need to know what step we are doing to switch validators in the Could you add the above |
Buttons with previous-step shows the preloader and hang up.
As another issue, I think the data-feedback function is not called on previous-step.
Background:
With 2.1.4 I used data-feedback for validation and the stepchange event to catch transition to setup next validator.
The stepchange event was sent after the transition both for next steps and prev steps. So I was able to setup validators using getActiveStep().
With 3.0.0 beta the stepchange event is sent for next steps before transition. I think no such event is sent for prev steps. So I'm trying to use data-feedback and it calls nextStep() and destroyFeedback(). Maybe that differs from your intention.
The text was updated successfully, but these errors were encountered: