Expand my Community achievements bar.

Join us for Adobe Campaign Community Q&A Coffee Break on Thursday, March 7th at 8am PT with Eric Perrin, Gael Mouello, Chakravarthy Kalva, Bruce Swann and Sandra Hausmann.

Dynamic field + bootstrap validation


Community Advisor

I am displaying/hiding form elements based on a user dropdown select option, the following script is meant to add/remove required attributes on the fields, however, it seems that validation is not taking this into account, could it be that validation script only runs on page load rather than on dynamic form changes? if so, how can I make it listen to changes in form required fields.




function MyOnChange(invesType){
  var x = document.getElementById("iProfessional");
  if (invesType != "privateClients") {
    x.style.display = "block";
  $('#companyname').prop('required', true)
  $('#jobtitle').prop('required', true)
    } else {
    x.style.display = "none";

 Upon submitting the form after the required and data-nl-ismandatory have been removed, Adobe Campaign is showing that these fields are mandatory.



1 Reply


Community Advisor

Hello @david--garcia 


Remove all "data-nl-mandatory" tags and validate everything with the javascript. nl tags won't consider the dynamic changes.

Remove the validation log from OnChange function and add the logic in the form Validation function. The form validation function will look like this

 function formValidation(){
	var jobTitle=$("#jobtitle").val();
	var companyname=$("#companyname").val();
			alert("Company Name is required"); // you may want show it in error div via innerHTML
			return false;


and the submit button will have this onclick attribute.

onclick="return formValidation()"


It should work in this case.





     Find me on LinkedIn