wbotelhos/stepy

Validation plugin tires to validate all enabled elements

Opened this issue · 4 comments

When a step is active most of the time its just that step that needs to be validated so you can change the line

$($step.find(':input:enabled').get().reverse()).each(function ()

to read

$($step.find(':input:enabled').not(":hidden").get().reverse()).each(function ()

This will only validate visible elements and not hidden steps. If you want more flexibility add a flag to properties for validatehidden:false and if someone wants that function they can set it to true (but i cant see any point of validating hidden fields)

Hi @farrukhsubhani,

Stepy validates the hidden fields because you can click to jump 3 step ahead, then all steps behind, that is hidden, should be validate to be continue.

Maybe we can just validates hidden fields, in that case when is possible jump steps by title click.

Most ruby and mvc asp.net framework generate a hidden field for checkboxes and using jquery validation plugin we can put in ignore case however in stepy the above line takes all enabled inputs. I have changed it to use opt.ignore string to respect ignore option. Which is same for validation plugin as well.

I have an anger about jQuery Validation about the hidden validation by default.
It causes a issue on Stepy, because we need what a told you: Validate hidden fields when we jump more than on stepy. I did a hack to avoid that default, but my intention is create the jQuery Validaty and integrates it on future.

Thinking about jumping more than one step and validating whole form. You can have an option flag in opt.vaidateall when true will not filter the fields.

There are two things here. 1. Validating fields and 2. Missing a step by jumping more than one.

If you seperate these two concerns then its easy to see why validation is actually not needed on hidden fieds.

For example you have steps array which you can also have step.status for each step as a property. Initialize it to 0. When you make your step visible you dont need to set it to anything. But when someone jumps to another step you can mark the leaving step as -1 if invalid and 1 if valid and check if the last step index is current index - 1 then its not a jump else loop through all step indexes in between and mark them as -1 because they were skipped.
You can also use a status array like

  • seen / visited
  • not seen
  • valid
  • skipped
  • invalid

All of these can have css classes to be set or not to reflect step status.

This way you only rely on jquery validation when required. Let me know if you think the approach is not right.