• 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.

How to apply validation class?

trb

Member
Hi -

I have 3 fields on my form which are related. All three are "watched" by a fourth element which determines the options presented in this fourth elements dropdown menu. If a validation error occurs on my first element (for example, the user leaves it blank, or in my case fills it in but then deletes it before submitting the form), I reset the second and third elements when the form reloads as they depend on the value of the first element.

When the form is submitted, the validation detects the empty first element and correctly highlights it in red, as it fails the validation, however the second and third elements which I reset are not highlighted with the red validation message.

My question is how can I apply the failed validation class to the 2nd and 3rd element, which I reset through my code, so that the user sees the red highlight text for all 3 elements and know they must re-enter all 3?

Thanks.
 
... I reset the second and third elements when the form reloads as they depend on the value of the first element.
... My question is how can I apply the failed validation class to the 2nd and 3rd element, which I reset through my code...
How do you "reset" the 2nd and 3rd element, where and what is your code?
Do you have validations for those elements?
 
Hi Lousyfool,

Thanks. I making an ajax call to a function which checks several conditions and returns a success or an error message. If error, I reset certain elements accordingly as shown below. In this case it is a radio button element. When I reset an element, I would like to highlight it in red, similar to the default form validation failure, to draw the users attention to it.

jQuery.ajax({
type: "post",
url: baseurl+"returningplayercheck.php?firstname="+firstname+"&lastname="+lastname+"&dob="+dateofbirth+"&last_reg="+didyouregisterval+"&form=football&coachescode="+coachesCode,
cache: false,
success: function(json){
var obj = JSON.parse(json);
var errmsg = obj.data.form;
var lastyeardistrict = obj.data.district;

if (errmsg=='age_err') {
alert('Your child does not meet the age requirements');
jQuery('input[name="jos_football_18_repeat___returning_register_last_year['+rownum+'][]"]').attr('checked',false);
}
 
Seems you're already manipulating the DOM with jQuery, so you can continue with the same approach and just add error class also with jQuery, e.g. something like:

if (errmsg=='age_err') {
alert('Your child does not meet the age requirements');
jQuery('input[name="jos_football_18_repeat___returning_register_last_year['+rownum+'][]"]').attr('checked',false);
jQuery(".fb_el_tablename_elementname").addClass("error").addClass("fabrikError");
}
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top