You are viewing limited content. For full access, please sign in.

Question

Question

Changing which input fields inside Address Block are required

asked on February 27, 2018

I have noticed on the address block that when you make the address field required. It makes all inputs inside the address block required EXCEPT "Address Line 2" . 

What if one of our clients wanted everything required except "Country" was not a Requirement? Or any of the other fields not a requirement but others you want to be required.  How would I do this?

Any help with this would be appreciated. Thank you!

0 0

Answer

SELECTED ANSWER
replied on February 27, 2018

In Google Chrome if you right-click inside of the field, you can get the id of that particular field. Then you can do the following:

$( document ).ready(function() {
  
  $('#Field1_DSG5').removeAttr("required"); //Country is not requried
  $('#Field1_DSG1').attr("required", true); //Address Line 2 is requried
  
}); //etc.

 

addressReqNotReq.PNG
address.png
address.png (10.07 KB)
1 0
replied on February 27, 2018

I will give this a try. Makes sense. Thank You so much for your quick response!

0 0
replied on February 27, 2018

This worked great! Thanks again! 

0 0
replied on February 27, 2018

Now this is NOT working after I have added the fields into a new collection I created and put the fields into.

 

So far for me this only works if the field is not inside a collection to where  for example the id="Field29"

 

If I add it into a collection it then changes it to "Field29(1)" . This is what it shows when I click on inspect in Chrome. 

 

<input type="text" id="Field29(1)" name="Field29(1)" aria-labelledby="Field29(1)" class="number cf-medium" maxlength="4000" vo="e" decimal-disabled="true" separator-disabled="false" data-parsley-valid-format="number" data-parsley-id="25">

 

 

Following is not working:

 

$( document ).ready(function() {
  
  $('#Field29(1)').attr("required", true); 
  
});

 

If I move it outside of collection and the id has no (1) it works fine. 

 

I really would like this to work with inside a collection. 

 

Thank you,

Andy

 

 

 

0 0
replied on February 27, 2018 Show version history

This should get you closer. 

Also, set the CSS value of the address to "address"

$( document ).ready(function() {
  
  setTimeout(chkCol, 1);

  $(document).on('click', '.cf-collection-append, cf-collection-delete', chkCol);
 
  function chkCol() {
  
  var i = 0;
    $('.address').each(function(index) {
  i++;
      
      $('#Field29\\(' + i + '\\)_DSG5').removeAttr("required"); //Country is not requried
      $('#Field29\\(' + i + '\\)_DSG1').attr("required", true); //Address Line 2 is requried

    });
  
}
  
});

 

addressInCollection.png
AddressCSSVAlue.png
1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.