• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Validation only if element is visible?

joit

Active Member
Hi,

I need to have a validation on an element that only validates if the element is not hidden with Javascript onload hide...

Is it possible?

Thanks
 
You can add a validation condition which is "replicating" your JS show condition.
 
Condition must return false if the validation should not be run.

So assuming your validation is on element1
and you have an element2 with JS "show element1 if this(element2)=='1'"
set the condition of your element1 to something like

if ('{your-table___element2_raw}' == '1') return true; //ie run the validation
return false; //dont' run
 
Condition must return false if the validation should not be run.

So true! The javascript just checks, if the username is empty or not (new account or account changes). So I probably don't need the if condition, just the state of the username field.

If I want to validate is this:
element user is filled out AND (user group is 10 OR 12)

So I tried something like this, but it won't work!

return ('{abcd_users___username}' != '') && ('{userdetails___user_group}'==10 || '{userdetails___user_group}'==12);

do you have a tip for me?
 
Is user_group a usergroups element?
Then {userdetails___user_group} will return a string with groups comma separated "1,5,12,13"
 
the user group part works fine, I tested that already. It doesn't work in combination with
"check if username isn't empty"
 
Ah, you are using {abcd_users___username}, I assume this is no element of your form but you have a user element userdetails___xy storing the userID?
Use this one for checking.
 
BTW, I'm working on a little improvement to add a "Don't validate if hidden by FX" option to the validations. So if you have a Javascript FX which hides an element or a group, the form will automatically track that, and (optionally) skip validation if an element was hidden on submit.

Won't be ready for a while, as it's not entirely trivial, but it's on the way. Something I've been meaning to do for literally years.

-- hugh
 
Jumpin' in here cause I'm not sure if I have the same need.

I want to hide/show a group based upon a dropdown. The idea is to more easily customize what needs to be filled out for a particular type of entry. I was worried that if I have elements in a hidden group that have "not empty" validations - they would still run. I was going to try it and see - but.....
 
Yes, correct. This thread is about exactly that. You need to check in the "Condition" for the validations on any fields in your (possibly) hidden group, to see if the value of the dropdown means that they would be hidden.

-- hugh
 
Okay - thanks. This, and my "hide tabs" challenge may drive me another way. There are actually quite a number of fields for each "group" and it would be a bit of coding to add this to each validation. It may be simpler to create groups and forms that are separate, using linked elements (child/parent) for the "common" ones. I need to think about that. The issue is we want some unified reporting - and if I separate them too much, that breaks.....
 
I'll be committing a change today some time to automate hiding / showing a tab when you hide / show its group.

And I'm working on a way of automating that "don't validate if hidden by JS FX" thing, although I can't promise an ETA for that.

-- hugh
 
Hey Hugh,

I know you said no "eta" on this. Any update. Since you fixed the tabs, I'm wanting to move forward with the system using the hidden tabs, but of course, I need to handle validation for hidden fields. It is made a bit more complex because some of the tabs will show copies (child elements) of some of the fields on a hidden tab.
 
OK, I just took an hour and figure out a relatively easy way to do it, which is fairly generic:

https://github.com/Fabrik/fabrik/commit/616b16473ba9c7282bc377b2f99cd30bea254884

The new "Validate Hidden" option defaults to Yes, so backward compatible with the existing behavior to always validate. If set to No, validation will be skipped if the element itself, or any ancestor (like the group or tab) has the fabrikHide class.

The element's status is checked during submission of the form, where we now iterate through all the formElements, and do a jQuery closest('.fabrikHide') on each element, and if that isn't empty, add the element name to a hidden input, that the sever side shouldValidate() method checks.

This works with the built in JS FX, as they add and remove that class to the element or group. It also makes it fairly easy for people to manipulate in custom code, by just adding or removing that class to whatever they want.

NOTE - I haven't tested this with repeat groups, multipages or tabbed templates yet. Just simple forms with simple test cases - JS FX to hide/show elements and groups.

Have a go, let me know.

-- hugh
 
@ontarget: meanwhile the validations have an option "validate hidden" (although I'm not sure if this is working also if you are hiding via JS)
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top