Validate Country from the Dropdown Data Source in Excel

Hi,

I hope anyone could help me. see interface below
image

I want to validate the country textfield and show the submit button if it exists. If it doesn't exist it will prompt an alert to inform and hide the submit button. The Dropdown is hidden.

here is the code that I have so far but its not working.

Dear @Bert,
The validator is running on submit only, you'll need a separate function to show/hide the button.

Something like this might work for hiding/showing submit button:

function showHideSubmit(){
  var countries = fd.field('Field1').widget.dataSource.data();
  fd.control('Submit1').hidden = true;
  for(var i = 0; i < countries.length; i++){
    if(fd.field('Country').value == countries[i].value){
      fd.control('Submit1').hidden = false;
    }
  }
}

fd.rendered(function(){
  fd.field('DropDown1').hidden = true;
  // Calling showHideSubmit when the Country value changes
  fd.field('Country').$on('change',showHideSubmit);

  // Calling showHideSubmit on form loading
  fd.control('Submit1').hidden = true;
  fd.field('DropDown1').$on('ready', function() {
    showHideSubmit();
  });
});

Hi @Nikita_Kurguzov ,

It works perfectly and thank you so much for your help. Also I was able to understand and learned from it. This community rocks!. Keep it up and more power to all of you.

1 Like