Support

Account

Home Forums Backend Issues (wp-admin) ACF- Error-Detection- mandatory fields jQuery

Unread

ACF- Error-Detection- mandatory fields jQuery

  • Hello guys and girls,
    first I wanna thank you for this great plugin.
    I’m using it for an Project-boerse and it’s working fantastic.

    But now I have a problem and maybe you can give me some advice.
    If I’m using your ACF-Plugin you can make fields as mandatory. If the mandatory field is not fill out, you get an error with a message and the fields are highlighted.

    This feature I would like to use with non ACF-Fields like the title and some taxonomy-checkboxes.
    Well I write some code with jQuery and check the non-ACF fields.
    If they are empty, it is creating the same error message and highlight as your plugin.

    But if I’m not fill out my mandatory fields at first, I get the same error detection but the mandatory fields from ACF-Plugin are not higlighted.

    So the questons are:
    First, how can I change the order from the scripts? So first check mandatory fields vom ACF and then from my own Javascript.

    Second, is there a way to check both mandatory fields from ACF-Plugin and wordpress in such a way that I can get the error-message and highlighting for both at the SAME TIME?
    Maybe I could change my Script and check all mandatory fields from ACF-Plugin, but this is duplicate.

    Thank you for helping and I’m srry for my bad english translation.

    Hier is the jQuery Code I have written so far:

    
    jQuery(document).ready(function(){
    	jQuery('#publish').click(function(){
    	console.log("Script Require Taxonomy v20");
    	//Anzahl der Buchstaben vom Titel ermitteln
    	var titlevar = jQuery('[id^=\"titlediv\"]').find('#title');
    	//Anzahl der Auswählbaren Elemente Fakultät bestimmen
    	var fakultaetvar = document.getElementsByName("tax_input[fakultaet]").length;
    	//Anzahl der Auswählbaren Elemente Fachgebiet bestimmen
    	var fachgebietvar = document.getElementsByName("tax_input[fachgebiet]").length;	
    	var errorvar = false;
    	
    //************************************CHECKT TITLE LENGTH******************************
    		if(titlevar.val().length > 50 || titlevar.val().length < 10)
    	{
    		console.log("Titel Fehler");
    			errorvar = true;
    			jQuery("#title").css({
    				"border":"1px solid #CC0000",
    				"background": "none repeat scroll 0 0 #FFEBE8",
    			});
    	} 
    		else
    	{
    		console.log("Titel OK");
    			//Setze CSS Eigneschaft wieder auf normal
    		jQuery("#title").css({
    			"border":"1px solid #E5E5E5",
    			"background": "none repeat scroll 0 0 #FFFFFF",
    		});
    	} 
    //************************************CHECKT RADIOBUTTONS FAKULTAET******************************
    		if(fakultaetvar > 0)
    	{
    			console.log(fakultaetvar);
    			for (var i = 0; i < fakultaetvar; i++)
    			{			
    	//Check if radiobuttons are checked
    				if(document.getElementsByName("tax_input[fakultaet]")[i].checked == true)
    				{
    				    console.log("Fakultät OK");
    				    //Setze CSS Eigenschaft auf normal
    				    jQuery("#customfakultaetdiv").css({
    						"border":"1px solid #E5E5E5",
    						"background": "none repeat scroll 0 0 #FFFFFF",
    					});
    				    
    				    break;
    				}
    				
    				if(i == (fakultaetvar - 1))
    				{
    					console.log("Fakultät nicht ausgewählt");
    					errorvar = true;
    jQuery("#customfakultaetdiv").css({
    "border":"1px solid #CC0000",
    "background": "none repeat scroll 0 0 #FFEBE8",
    					});
    					break;
    				}
    				console.log(i);
    			}		
    	}
    //********************CHECKT RADIOBUTTONS FACHGEBIET******************************
    		if(fachgebietvar > 0)
    	{
    			console.log(fachgebietvar);
    			for (var i = 0; i < fachgebietvar; i++)
    			{			
    	//Check if radiobuttons are checked
    				if(document.getElementsByName("tax_input[fachgebiet]")[i].checked == true)
    				{
    				    console.log("Fachgebiet OK");
    				    jQuery("#customfachgebietdiv").css({
    						"border":"1px solid #E5E5E5",
    						"background": "none repeat scroll 0 0 #FFFFFF",
    					});
    					break;
    				}
    				
    				if(i == (fachgebietvar - 1))
    				{
    					console.log("Fachgebiet nicht ausgewählt");
    					errorvar = true;
    					jQuery("#customfachgebietdiv").css({
    						"border":"1px solid #CC0000",
    						"background": "none repeat scroll 0 0 #FFEBE8",
    					});
    					//jQuery("#customfachgebietdiv").addClass("backend-error");
    					break;
    				}
    				console.log(i);
    			}		
    	}	
    	//Check boolean
    		if(errorvar == true){
    			console.log("FEHLER");
    			//Überprüfe ob die Warnhinweis Box bereits aktiv ist, wenn ncht erzeuge diese
    			if(jQuery("#message").length == 0)
    			{
    				jQuery("<div id='message' class='error'><p>Fehler bei Überprüfung: Ein oder mehrere Felder werden benötigt.</p></div>").insertBefore("#post");
    			}
    // hide ajax stuff on submit button
    jQuery("#publish").removeClass('button-primary-disabled');
    jQuery('#publishing-action .spinner').hide();
    return false;
    		}else{
    			console.log("ALL OK");
    			return true;
    		}
    	});
    });
    
Viewing 1 post (of 1 total)

The topic ‘ACF- Error-Detection- mandatory fields jQuery’ is closed to new replies.