Stop Validating Hidden

Status
Not open for further replies.
Hello.
I am controlling the visibility of various elements using the following JS code placed in form_X.js.
JavaScript:
function hideElement(target) {  jQuery(target.element).closest('.fabrikElementContainer').addClass('fabrikHide');
}

function showElement(target) {  jQuery(target.element).closest('.fabrikElementContainer').removeClass('fabrikHide');
}

The visibility aspect works as expected, although the validation for hidden elements doesn't stop even after setting 'No' for the Validate Hidden.
Am I missing something, or is there an issue with the above JS code?
 
What you're trying to do by adding the fabrikHide class in form_X.js merely hides the element container per "display:none;". By the time this happens, it might be too late as "Validate Hidden" seems to have done its check already.
Instead of form_X.js, can't you use the element JS for show/hide?
 
Dear @lousyfool... Thanks for your interest and answer.
I see what you are stating, but that would mean a fundamental flaw in how validation is implemented. And let me give you an example.

Let's assume that we have a radiobutton with 2 possible options. Option A and Option B.
And then there is another text input which is hidden from the very load and appears only if Option A is selected (it this doesn't appear if Option B is selected). And this text input is mandatory if Option A was selected.

Now as per your explanation, irrespective of using form_X or element JS for show/hide, the check whether to do the validation needs to happen at submission... So if Option A was selected, the text box would have been visible and was mandatory for the user to input data... And vice-versa.

If the "Validate Hidden" works at load time, then it won't work correctly. Isn't it?

Hope it makes sense! :)
 
I understand what you're saying, but that's not the way it works, or should work.
Again, with your adding the "fabrikHide" class to an element container via form_X.js, you're only adding "display:none;" at a time when the validation is already set for the element. At this point, the form won't submit if that field doesn't validate, if you see it in the browser or not.
Otherwise, you'd be able to add a "display:none;" in your browser console and then skip the validation of such field... making any validation pointless.

"Validate Hidden" refers, as per tooltip, to the element JS. Using this, it's integrated in the code and can work. So, again, can't you use the element JS instead of form_X.js? Your example reads as if it's well possible.
 
"Otherwise, you'd be able to add a "display:none;" in your browser console and then skip the validation of such field... making any validation pointless." Hmm... I see...! :O
I can definitely add element JS (instead of form_X.js) and on load and change, just that it was convinient and clean to have all custom code in a separate file.
But this brings me to the following question... And I will refer to the example in my last post:
By using element JS (instead of form_X.js), if I show/hide the text box based upon the value of the radiobutton, will "Visible Hidden" pick up the show/hide and decide on the validation? Or I need to actually change my implementation and be thinking of using "Validation Condition" to check the value of the radio box... It shall be a completely different implementation, TBH!
 
You mean "Validate Hidden", still? Please read the tooltip there.

If you're having a case which, in reality, is different from your example, so element JS incl Validate Hidden can't be used, you'll need to perform more trickery in your custom JS, indeed.
 
Oops.... Yes I meant "Validate Hidden".
The code in the first post was a function in form_X.js which I call several times, such as at:
1. Load to hide elements
2. Change/Click event on a primary element to hide or show another dependent element (based upon value selected or entered in the primary element)

I will indeed look at "Condition" and add some php code to decide whether to validate or not.
 
Yes, validation condition is the way to go in this case, e.g.: return {mytable___radiobutton_element} == myvalue;
 
Thanks @juuser and @lousyfool... I have managed to get this running, but crash landed into other issues related to loss of data at validation failure on the last page of a multipage form.
Have opened another thread. I shall close this one. Thanks again!
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top